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)
| 147 | return pose_avg |
| 148 | |
| 149 | def center_poses(poses, pose_avg_from_file=None): |
| 150 | """ |
| 151 | Center the poses so that we can use NDC. |
| 152 | See https://github.com/bmild/nerf/issues/34 |
| 153 | |
| 154 | Inputs: |
| 155 | poses: (N_images, 3, 4) |
| 156 | pose_avg_from_file: if not None, pose_avg is loaded from pose_avg_stats.txt |
| 157 | |
| 158 | Outputs: |
| 159 | poses_centered: (N_images, 3, 4) the centered poses |
| 160 | pose_avg: (3, 4) the average pose |
| 161 | """ |
| 162 | |
| 163 | |
| 164 | if pose_avg_from_file is None: |
| 165 | pose_avg = average_poses(poses) # (3, 4) # this need to be fixed throughout dataset |
| 166 | else: |
| 167 | pose_avg = pose_avg_from_file |
| 168 | |
| 169 | pose_avg_homo = np.eye(4) |
| 170 | pose_avg_homo[:3] = pose_avg # convert to homogeneous coordinate for faster computation (4,4) |
| 171 | # by simply adding 0, 0, 0, 1 as the last row |
| 172 | last_row = np.tile(np.array([0, 0, 0, 1]), (len(poses), 1, 1)) # (N_images, 1, 4) |
| 173 | poses_homo = \ |
| 174 | np.concatenate([poses, last_row], 1) # (N_images, 4, 4) homogeneous coordinate |
| 175 | |
| 176 | poses_centered = np.linalg.inv(pose_avg_homo) @ poses_homo # (N_images, 4, 4) |
| 177 | poses_centered = poses_centered[:, :3] # (N_images, 3, 4) |
| 178 | |
| 179 | return poses_centered, pose_avg #np.linalg.inv(pose_avg_homo) |
| 180 | |
| 181 | def render_path_spiral(c2w, up, rads, focal, zdelta, zrate, rots, N): |
| 182 | render_poses = [] |
no test coverage detected