Transforms poses so principal components lie on XYZ axes. Args: poses: a (N, 3, 4) array containing the cameras' camera to world transforms. Returns: A tuple (poses, transform), with the transformed poses and the applied camera_to_world transforms.
(poses)
| 87 | |
| 88 | |
| 89 | def transform_poses_pca(poses): |
| 90 | """Transforms poses so principal components lie on XYZ axes. |
| 91 | |
| 92 | Args: |
| 93 | poses: a (N, 3, 4) array containing the cameras' camera to world transforms. |
| 94 | |
| 95 | Returns: |
| 96 | A tuple (poses, transform), with the transformed poses and the applied |
| 97 | camera_to_world transforms. |
| 98 | """ |
| 99 | t = poses[:, :3, 3] |
| 100 | t_mean = t.mean(axis=0) |
| 101 | t = t - t_mean |
| 102 | |
| 103 | eigval, eigvec = np.linalg.eig(t.T @ t) |
| 104 | # Sort eigenvectors in order of largest to smallest eigenvalue. |
| 105 | inds = np.argsort(eigval)[::-1] |
| 106 | eigvec = eigvec[:, inds] |
| 107 | rot = eigvec.T |
| 108 | if np.linalg.det(rot) < 0: |
| 109 | rot = np.diag(np.array([1, 1, -1])) @ rot |
| 110 | |
| 111 | transform = np.concatenate([rot, rot @ -t_mean[:, None]], -1) |
| 112 | poses_recentered = unpad_poses(transform @ pad_poses(poses)) |
| 113 | transform = np.concatenate([transform, np.eye(4)[3:]], axis=0) |
| 114 | |
| 115 | # Flip coordinate system if z component of y-axis is negative |
| 116 | if poses_recentered.mean(axis=0)[2, 1] < 0: |
| 117 | poses_recentered = np.diag(np.array([1, -1, -1])) @ poses_recentered |
| 118 | transform = np.diag(np.array([1, -1, -1, 1])) @ transform |
| 119 | |
| 120 | # Just make sure it's it in the [-1, 1]^3 cube |
| 121 | scale_factor = 1. / np.max(np.abs(poses_recentered[:, :3, 3])) |
| 122 | poses_recentered[:, :3, 3] *= scale_factor |
| 123 | transform = np.diag(np.array([scale_factor] * 3 + [1])) @ transform |
| 124 | |
| 125 | return poses_recentered, transform |
| 126 | |
| 127 | def generate_interpolated_path(poses, n_interp, spline_degree=5, |
| 128 | smoothness=.03, rot_weight=.1): |
nothing calls this directly
no test coverage detected