Project 3D points to 2D following the OpenCV convention Args: points (np.ndarray): [..., N, 3] or [..., N, 4] 3D points to project, if the last dimension is 4, the points are assumed to be in homogeneous coordinates extrinsics (np.ndarray): [..., 4, 4] extrinsic
(
points: np.ndarray,
extrinsics: np.ndarray = None,
intrinsics: np.ndarray = None
)
| 581 | |
| 582 | @batched(2,2,2) |
| 583 | def project_cv( |
| 584 | points: np.ndarray, |
| 585 | extrinsics: np.ndarray = None, |
| 586 | intrinsics: np.ndarray = None |
| 587 | ) -> Tuple[np.ndarray, np.ndarray]: |
| 588 | """ |
| 589 | Project 3D points to 2D following the OpenCV convention |
| 590 | |
| 591 | Args: |
| 592 | points (np.ndarray): [..., N, 3] or [..., N, 4] 3D points to project, if the last |
| 593 | dimension is 4, the points are assumed to be in homogeneous coordinates |
| 594 | extrinsics (np.ndarray): [..., 4, 4] extrinsics matrix |
| 595 | intrinsics (np.ndarray): [..., 3, 3] intrinsics matrix |
| 596 | |
| 597 | Returns: |
| 598 | uv_coord (np.ndarray): [..., N, 2] uv coordinates, value ranging in [0, 1]. |
| 599 | The origin (0., 0.) is corresponding to the left & top |
| 600 | linear_depth (np.ndarray): [..., N] linear depth |
| 601 | """ |
| 602 | assert intrinsics is not None, "intrinsics matrix is required" |
| 603 | if points.shape[-1] == 3: |
| 604 | points = np.concatenate([points, np.ones_like(points[..., :1])], axis=-1) |
| 605 | if extrinsics is not None: |
| 606 | points = points @ extrinsics.swapaxes(-1, -2) |
| 607 | points = points[..., :3] @ intrinsics.swapaxes(-1, -2) |
| 608 | with no_warnings(): |
| 609 | uv_coord = points[..., :2] / points[..., 2:] |
| 610 | linear_depth = points[..., 2] |
| 611 | return uv_coord, linear_depth |
| 612 | |
| 613 | |
| 614 | @batched(2,2,2,2) |
nothing calls this directly
no test coverage detected