Calculate the average pose, which is then used to center all poses using @center_poses. Its computation is as follows: 1. Compute the center: the average of pose centers. 2. Compute the z axis: the normalized average z axis. 3. Compute axis y': the average y axis. 4. Compute
(poses)
| 118 | return v / np.linalg.norm(v) |
| 119 | |
| 120 | def average_poses(poses): |
| 121 | """ |
| 122 | Calculate the average pose, which is then used to center all poses |
| 123 | using @center_poses. Its computation is as follows: |
| 124 | 1. Compute the center: the average of pose centers. |
| 125 | 2. Compute the z axis: the normalized average z axis. |
| 126 | 3. Compute axis y': the average y axis. |
| 127 | 4. Compute x' = y' cross product z, then normalize it as the x axis. |
| 128 | 5. Compute the y axis: z cross product x. |
| 129 | Note that at step 3, we cannot directly use y' as y axis since it's |
| 130 | not necessarily orthogonal to z axis. We need to pass from x to y. |
| 131 | Inputs: |
| 132 | poses: (N_images, 3, 4) |
| 133 | Outputs: |
| 134 | pose_avg: (3, 4) the average pose |
| 135 | """ |
| 136 | # 1. Compute the center |
| 137 | center = poses[..., 3].mean(0) # (3) |
| 138 | # 2. Compute the z axis |
| 139 | z = normalize(poses[..., 2].mean(0)) # (3) |
| 140 | # 3. Compute axis y' (no need to normalize as it's not the final output) |
| 141 | y_ = poses[..., 1].mean(0) # (3) |
| 142 | # 4. Compute the x axis |
| 143 | x = normalize(np.cross(y_, z)) # (3) |
| 144 | # 5. Compute the y axis (as z and x are normalized, y is already of norm 1) |
| 145 | y = np.cross(z, x) # (3) |
| 146 | pose_avg = np.stack([x, y, z, center], 1) # (3, 4) |
| 147 | return pose_avg |
| 148 | |
| 149 | def center_poses(poses, pose_avg_from_file=None): |
| 150 | """ |
no test coverage detected