Compute the image coordinates of the 3D points in the world. Args: xyz_w: (*b_shape, *n_shape, 3) the points in world coordinate intrinsics: (*b_shape, *m_shape, 3, 3) the camera intrinsics H_c2w: (*b_shape, *m_shape, 4, 4) homege
(
xyz_w: torch.Tensor,
intrinsics: torch.Tensor,
H_c2w: torch.Tensor,
dim_b: int = 0,
)
| 1197 | |
| 1198 | |
| 1199 | def pinhole_projection( |
| 1200 | xyz_w: torch.Tensor, |
| 1201 | intrinsics: torch.Tensor, |
| 1202 | H_c2w: torch.Tensor, |
| 1203 | dim_b: int = 0, |
| 1204 | ) -> torch.Tensor: |
| 1205 | """ |
| 1206 | Compute the image coordinates of the 3D points in the world. |
| 1207 | |
| 1208 | Args: |
| 1209 | xyz_w: |
| 1210 | (*b_shape, *n_shape, 3) the points in world coordinate |
| 1211 | intrinsics: |
| 1212 | (*b_shape, *m_shape, 3, 3) the camera intrinsics |
| 1213 | H_c2w: |
| 1214 | (*b_shape, *m_shape, 4, 4) homegeneous matrix (camera -> world) |
| 1215 | dim_b: |
| 1216 | length of b_shape |
| 1217 | Returns: |
| 1218 | (*b_shape, *m_shape, *n_shape, 2) (col, row) on the images, can be outside of the image boundary |
| 1219 | """ |
| 1220 | *bn_shape, _ = xyz_w.shape |
| 1221 | *bm_shape, _, _ = intrinsics.shape |
| 1222 | n_shape = bn_shape[dim_b:] |
| 1223 | m_shape = bm_shape[dim_b:] |
| 1224 | assert bn_shape[:dim_b] == bm_shape[:dim_b] |
| 1225 | b_shape = bn_shape[:dim_b] |
| 1226 | |
| 1227 | H_w2c = rigid_motion.inv_homogeneous_tensors(H_c2w) # (*b, *m, 4, 4) |
| 1228 | H_w2c = H_w2c.reshape(*b_shape, *m_shape, *([1] * len(n_shape)), 4, 4) # (*b, *m, *n, 4, 4) |
| 1229 | intrinsics = intrinsics.reshape(*b_shape, *m_shape, *([1] * len(n_shape)), 3, 3) # (*b, *m, *n, 3, 3) |
| 1230 | xyz_w = torch.cat( |
| 1231 | [ |
| 1232 | xyz_w, # (*b, *n, 3) |
| 1233 | torch.ones(*b_shape, *n_shape, 1, device=xyz_w.device, dtype=xyz_w.dtype), |
| 1234 | ], dim=-1) # (*b, *n, 4) |
| 1235 | xyz_w = xyz_w.reshape(*b_shape, *([1] * len(m_shape)), *n_shape, 4, 1) # (*b, *m, *n, 4, 1) |
| 1236 | xyz_c = H_w2c @ xyz_w # (*b, *m, *n, 4, 1) |
| 1237 | uvw_c = intrinsics @ xyz_c[..., :3, :] # (*b, *m, *n, 3, 1) |
| 1238 | uv_c = uvw_c[..., :2, 0] / uvw_c[..., 2:3, 0] # (*b, *m, *n, 2) |
| 1239 | return uv_c |
| 1240 | |
| 1241 | |
| 1242 | def find_corresponding_uv( |
no test coverage detected