Center the poses so that we can use NDC. See https://github.com/bmild/nerf/issues/34 Inputs: poses: (N_images, 3, 4) pose_avg_from_file: if not None, pose_avg is loaded from pose_avg_stats.txt Outputs: poses_centered: (N_images, 3, 4) the centered poses
(poses, pose_avg_from_file=None)
| 165 | return pose_avg |
| 166 | |
| 167 | def center_poses(poses, pose_avg_from_file=None): |
| 168 | """ |
| 169 | Center the poses so that we can use NDC. |
| 170 | See https://github.com/bmild/nerf/issues/34 |
| 171 | |
| 172 | Inputs: |
| 173 | poses: (N_images, 3, 4) |
| 174 | pose_avg_from_file: if not None, pose_avg is loaded from pose_avg_stats.txt |
| 175 | |
| 176 | Outputs: |
| 177 | poses_centered: (N_images, 3, 4) the centered poses |
| 178 | pose_avg: (3, 4) the average pose |
| 179 | """ |
| 180 | |
| 181 | |
| 182 | if pose_avg_from_file is None: |
| 183 | pose_avg = average_poses(poses) # (3, 4) # this need to be fixed throughout dataset |
| 184 | else: |
| 185 | pose_avg = pose_avg_from_file |
| 186 | |
| 187 | pose_avg_homo = np.eye(4) |
| 188 | pose_avg_homo[:3] = pose_avg # convert to homogeneous coordinate for faster computation (4,4) |
| 189 | # by simply adding 0, 0, 0, 1 as the last row |
| 190 | last_row = np.tile(np.array([0, 0, 0, 1]), (len(poses), 1, 1)) # (N_images, 1, 4) |
| 191 | poses_homo = \ |
| 192 | np.concatenate([poses, last_row], 1) # (N_images, 4, 4) homogeneous coordinate |
| 193 | |
| 194 | poses_centered = np.linalg.inv(pose_avg_homo) @ poses_homo # (N_images, 4, 4) |
| 195 | poses_centered = poses_centered[:, :3] # (N_images, 3, 4) |
| 196 | |
| 197 | return poses_centered, pose_avg #np.linalg.inv(pose_avg_homo) |
| 198 | |
| 199 | def render_path_spiral(c2w, up, rads, focal, zdelta, zrate, rots, N): |
| 200 | render_poses = [] |
no test coverage detected