r"""Process siamese motion sequences. The code is borrowed from https://github.com/tr3e/InterGen/blob/master/utils/utils.py
| 58 | |
| 59 | @PIPELINES.register_module() |
| 60 | class ProcessSiameseMotion(object): |
| 61 | r"""Process siamese motion sequences. |
| 62 | The code is borrowed from |
| 63 | https://github.com/tr3e/InterGen/blob/master/utils/utils.py |
| 64 | """ |
| 65 | |
| 66 | def __init__(self, feet_threshold, prev_frames, n_joints, prob): |
| 67 | self.feet_threshold = feet_threshold |
| 68 | self.prev_frames = prev_frames |
| 69 | self.n_joints = n_joints |
| 70 | self.prob = prob |
| 71 | |
| 72 | def process_single_motion(self, motion): |
| 73 | feet_thre = self.feet_threshold |
| 74 | prev_frames = self.prev_frames |
| 75 | n_joints = self.n_joints |
| 76 | '''Uniform Skeleton''' |
| 77 | # positions = uniform_skeleton(positions, tgt_offsets) |
| 78 | |
| 79 | positions = motion[:, :n_joints * 3].reshape(-1, n_joints, 3) |
| 80 | rotations = motion[:, n_joints * 3:] |
| 81 | |
| 82 | positions = np.einsum("mn, tjn->tjm", trans_matrix, positions) |
| 83 | '''Put on Floor''' |
| 84 | floor_height = positions.min(axis=0).min(axis=0)[1] |
| 85 | positions[:, :, 1] -= floor_height |
| 86 | '''XZ at origin''' |
| 87 | root_pos_init = positions[prev_frames] |
| 88 | root_pose_init_xz = root_pos_init[0] * np.array([1, 0, 1]) |
| 89 | positions = positions - root_pose_init_xz |
| 90 | '''All initially face Z+''' |
| 91 | r_hip, l_hip, sdr_r, sdr_l = face_joint_indx |
| 92 | across = root_pos_init[r_hip] - root_pos_init[l_hip] |
| 93 | across = across / np.sqrt((across**2).sum(axis=-1))[..., np.newaxis] |
| 94 | |
| 95 | # forward (3,), rotate around y-axis |
| 96 | forward_init = np.cross(np.array([[0, 1, 0]]), across, axis=-1) |
| 97 | # forward (3,) |
| 98 | forward_init = forward_init / np.sqrt((forward_init**2).sum(axis=-1)) |
| 99 | forward_init = forward_init[..., np.newaxis] |
| 100 | |
| 101 | target = np.array([[0, 0, 1]]) |
| 102 | root_quat_init = qbetween_np(forward_init, target) |
| 103 | root_quat_init_for_all = \ |
| 104 | np.ones(positions.shape[:-1] + (4,)) * root_quat_init |
| 105 | |
| 106 | positions = qrot_np(root_quat_init_for_all, positions) |
| 107 | """ Get Foot Contacts """ |
| 108 | |
| 109 | def foot_detect(positions, thres): |
| 110 | velfactor, heightfactor = \ |
| 111 | np.array([thres, thres]), np.array([0.12, 0.05]) |
| 112 | |
| 113 | feet_l_x = \ |
| 114 | (positions[1:, fid_l, 0] - positions[:-1, fid_l, 0]) ** 2 |
| 115 | feet_l_y = \ |
| 116 | (positions[1:, fid_l, 1] - positions[:-1, fid_l, 1]) ** 2 |
| 117 | feet_l_z = \ |
nothing calls this directly
no outgoing calls
no test coverage detected