This repository has been archived by the owner on Feb 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
generate_stitched_video.py
81 lines (67 loc) · 3.11 KB
/
generate_stitched_video.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from __future__ import absolute_import, division, print_function, unicode_literals
import json
import numpy as np
from visualize import visualizeKeypoints
import argparse
'''
Example Run
python generateStitchedVideo.py --vidtype piano --body_path final_body/body_data.json
--righthand_path final_righthand/righthand_data.json
--lefthand_path final_lefthand/lefthand_data.json
--vid_path viz/all_pts.mp4 --pred_path viz/just_pred.mp4
--audio_path audio.wav
'''
def stitchHandsToBody(body_keyps, rh_keyps, lh_keyps):
body_keyps = np.array(body_keyps)
rh_keyps = np.array(rh_keyps)
lh_keyps = np.array(lh_keyps)
for ind, pts in enumerate(body_keyps):
rh_diff = np.expand_dims(pts[:, 2] - rh_keyps[ind][:, 0], axis=1)
lh_diff = np.expand_dims(pts[:, 5] - lh_keyps[ind][:, 0], axis=1)
rh_keyps[ind] = rh_keyps[ind] + rh_diff
lh_keyps[ind] = lh_keyps[ind] + lh_diff
return body_keyps, rh_keyps, lh_keyps
def createOptions():
# Default configuration for PianoNet
parser = argparse.ArgumentParser(
description="Pytorch: Audio To Body Dynamics Model"
)
parser.add_argument("--body_path", type=str, default="body_data.json",
help="Path to body keypoints")
parser.add_argument("--righthand_path", type=str, default="righthand_data.json",
help="Path to righthand keypoints")
parser.add_argument("--lefthand_path", type=str, default="lefthand_data.json",
help="Path to righthand keypoints")
parser.add_argument("--gt_path", type=str, default="ground_truth.mp4",
help="Where to save the ground_truth video.")
parser.add_argument("--pred_path", type=str, default="predictions.mp4",
help="Where to save the resulting prediction video.")
parser.add_argument("--vidtype", type=str, default='piano',
help="Type of video whether piano or violin")
parser.add_argument("--audio_path", type=str, default=None,
help="Only in for Test. Location audio file for"
" generating test video")
args = parser.parse_args()
return args
def main():
args = createOptions()
body = json.load(open(args.body_path, 'r+'))
righthand = json.load(open(args.righthand_path, 'r+'))
lefthand = json.load(open(args.lefthand_path, 'r+'))
all_pred_pts = np.concatenate(stitchHandsToBody(body[1], righthand[1],
lefthand[1]), axis=2)
all_targ_pts = np.concatenate((body[0], righthand[0], lefthand[0]), axis=2)
# Just Gt
visualizeKeypoints(args.vidtype, all_targ_pts, all_pred_pts,
args.audio_path, args.gt_path, show_pred=False)
# Just Pred
visualizeKeypoints(args.vidtype, all_targ_pts, all_pred_pts, args.audio_path,
args.pred_path, show_gt=False)
if __name__ == '__main__':
main()