MCPcopy
hub / github.com/OpenMotionLab/MotionGPT / render_motion

Function render_motion

app.py:76–135  ·  view source on GitHub ↗
(data, feats, method='fast')

Source from the content-addressed store, hash-verified

74
75
76def render_motion(data, feats, method='fast'):
77 fname = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(
78 time.time())) + str(np.random.randint(10000, 99999))
79 video_fname = fname + '.mp4'
80 feats_fname = fname + '.npy'
81 output_npy_path = os.path.join(output_dir, feats_fname)
82 output_mp4_path = os.path.join(output_dir, video_fname)
83 np.save(output_npy_path, feats)
84
85 if method == 'slow':
86 if len(data.shape) == 4:
87 data = data[0]
88 data = data - data[0, 0]
89 pose_generator = HybrIKJointsToRotmat()
90 pose = pose_generator(data)
91 pose = np.concatenate([
92 pose,
93 np.stack([np.stack([np.eye(3)] * pose.shape[0], 0)] * 2, 1)
94 ], 1)
95 shape = [768, 768]
96 render = SMPLRender(cfg.RENDER.SMPL_MODEL_PATH)
97
98 if not os.environ.get("PYOPENGL_PLATFORM"):
99 os.environ["DISPLAY"] = ":0.0"
100 os.environ["PYOPENGL_PLATFORM"] = "egl"
101
102 size = (shape[1], shape[0])
103 fps = 20.0
104 fourcc = cv2.VideoWriter_fourcc('M', 'P', '4', 'V')
105 videoWriter = cv2.VideoWriter(output_mp4_path, fourcc, fps, size)
106 r = RRR.from_rotvec(np.array([np.pi, 0.0, 0.0]))
107 pose[:, 0] = np.matmul(r.as_matrix().reshape(1, 3, 3), pose[:, 0])
108 for i in range(data.shape[0]):
109 img = np.zeros([shape[0], shape[1], 3])
110 aroot = data[[i], 0] + np.array([[0.0, 0.0, 30.0]])
111 aroot[:, 1] = -aroot[:, 1]
112 params = dict(pred_shape=np.zeros([1, 10]),
113 pred_root=aroot,
114 pred_pose=pose[[i]])
115 renderImg = render.render(img.copy(), params)
116 renderImg = (renderImg * 255).astype(np.uint8)
117 videoWriter.write(renderImg)
118 videoWriter.release()
119 output_video_h264_name = output_mp4_path[:-4] + '_h264.mp4'
120 command = 'ffmpeg -y -i {} -vcodec h264 {}'.format(
121 output_mp4_path, output_video_h264_name)
122 os.system(command)
123 output_mp4_path = output_video_h264_name
124 video_fname = video_fname[:-4] + '_h264.mp4'
125 elif method == 'fast':
126 output_gif_path = output_mp4_path[:-4] + '.gif'
127 if len(data.shape) == 3:
128 data = data[None]
129 if isinstance(data, torch.Tensor):
130 data = data.cpu().numpy()
131 pose_vis = plot_3d.draw_to_batch(data, [''], [output_gif_path])
132 out_video = mp.VideoFileClip(output_gif_path)
133 out_video.write_videofile(output_mp4_path)

Callers 2

load_motionFunction · 0.85
botFunction · 0.85

Calls 5

renderMethod · 0.95
SMPLRenderClass · 0.90
saveMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected