This function computes the perspective projection of a set of points. Input: points (bs, N, 3): 3D points rotation (bs, 3, 3): Camera rotation translation (bs, 3): Camera translation focal_length (bs,) or scalar: Focal length camera_center (bs, 2): Camera
(points, rotation, translation, focal_length,
camera_center)
| 245 | |
| 246 | |
| 247 | def perspective_projection(points, rotation, translation, focal_length, |
| 248 | camera_center): |
| 249 | """This function computes the perspective projection of a set of points. |
| 250 | |
| 251 | Input: |
| 252 | points (bs, N, 3): 3D points |
| 253 | rotation (bs, 3, 3): Camera rotation |
| 254 | translation (bs, 3): Camera translation |
| 255 | focal_length (bs,) or scalar: Focal length |
| 256 | camera_center (bs, 2): Camera center |
| 257 | """ |
| 258 | batch_size = points.shape[0] |
| 259 | K = torch.zeros([batch_size, 3, 3], device=points.device) |
| 260 | K[:, 0, 0] = focal_length |
| 261 | K[:, 1, 1] = focal_length |
| 262 | K[:, 2, 2] = 1. |
| 263 | K[:, :-1, -1] = camera_center |
| 264 | |
| 265 | # Transform points |
| 266 | points = torch.einsum('bij,bkj->bki', rotation, points) |
| 267 | points = points + translation.unsqueeze(1) |
| 268 | |
| 269 | # Apply perspective distortion |
| 270 | projected_points = points / points[:, :, -1].unsqueeze(-1) |
| 271 | |
| 272 | # Apply camera intrinsics |
| 273 | projected_points = torch.einsum('bij,bkj->bki', K, projected_points) |
| 274 | |
| 275 | return projected_points[:, :, :-1] |
| 276 | |
| 277 | |
| 278 | def estimate_translation_np(S, |
no outgoing calls
no test coverage detected