(hmr_motion, intrinsic, to_cpu=True, set_floor=False)
| 184 | return motion, joints[:-1], R_inv, delta_transl |
| 185 | |
| 186 | def 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 |
no test coverage detected