MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / process_hmr_motion

Function process_hmr_motion

motion_rep/retarget_motion.py:186–215  ·  view source on GitHub ↗
(hmr_motion, intrinsic, to_cpu=True, set_floor=False)

Source from the content-addressed store, hash-verified

184 return motion, joints[:-1], R_inv, delta_transl
185
186def process_hmr_motion(hmr_motion, intrinsic, to_cpu=True, set_floor=False):
187 new_data = {}
188 device = hmr_motion.device
189 seq_len = hmr_motion.shape[0]
190 # Step1: hmr -> amass
191 R_motionx_to_amass = torch.tensor([[-1, 0, 0], [0, 0, -1], [0, -1, 0]], dtype=torch.float32, device=device)
192 smpl_params, original_joints = motion_rep_to_SMPL(hmr_motion, equal_length=True)
193 joints_amass = torch.matmul(R_motionx_to_amass[None, None, :, :], original_joints.unsqueeze(-1)).squeeze(-1)
194 smpl_params_amass = apply_rotation(smpl_params, R_motionx_to_amass)
195
196 # Step2: amass -> dart
197 aligned_motion, joints_canonical, R_inv, delta_transl = canonicalize_motion(smpl_params_amass, joints_amass, set_floor=set_floor)
198 new_data['motion'] = aligned_motion.detach()
199 # rotation
200 extrinsic_R = torch.tensor([[1.0, 0.0, 0.0],
201 [0.0, 0.0, -1.0],
202 [0.0, 1.0, 0.0]], dtype=torch.float32, device=device)
203 extrinsic_R = mat3x3_to_rot6d(torch.matmul(R_inv, extrinsic_R)[None,]).repeat(seq_len, 1)
204 # translation
205 extrinsic_T = - torch.matmul(delta_transl, R_inv)[:, [0,2,1]]
206 extrinsic_T[0, 2] *= -1
207 extrinsic_T = extrinsic_T.repeat(seq_len, 1)
208
209 extrinsic = torch.cat([extrinsic_R, extrinsic_T], dim=-1)
210 new_data['extrinsic'] = extrinsic.detach()
211 new_data['intrinsic'] = intrinsic.detach()
212 if to_cpu:
213 new_data = {k: v.cpu() for k, v in new_data.items()}
214
215 return new_data, joints_canonical

Callers 1

convert_hmr_to_motionFunction · 0.90

Calls 4

motion_rep_to_SMPLFunction · 0.85
apply_rotationFunction · 0.85
canonicalize_motionFunction · 0.85
mat3x3_to_rot6dFunction · 0.85

Tested by

no test coverage detected