Project 3d points to image. Args: points3d (Union[np.ndarray, torch.Tensor]): shape could be (..., 3). cameras (CamerasBase): pytorch3d cameras or mmhuman3d cameras. resolution (Iterable[int]): (height, width) for rectangle or width for square. K (Uni
(points3d: Union[np.ndarray, torch.Tensor],
cameras: CamerasBase = None,
resolution: Iterable[int] = None,
K: Union[torch.Tensor, np.ndarray] = None,
R: Union[torch.Tensor, np.ndarray] = None,
T: Union[torch.Tensor, np.ndarray] = None,
convention: str = 'opencv',
in_ndc: bool = False)
| 160 | |
| 161 | |
| 162 | def project_points(points3d: Union[np.ndarray, torch.Tensor], |
| 163 | cameras: CamerasBase = None, |
| 164 | resolution: Iterable[int] = None, |
| 165 | K: Union[torch.Tensor, np.ndarray] = None, |
| 166 | R: Union[torch.Tensor, np.ndarray] = None, |
| 167 | T: Union[torch.Tensor, np.ndarray] = None, |
| 168 | convention: str = 'opencv', |
| 169 | in_ndc: bool = False) -> Union[torch.Tensor, np.ndarray]: |
| 170 | """Project 3d points to image. |
| 171 | |
| 172 | Args: |
| 173 | points3d (Union[np.ndarray, torch.Tensor]): shape could be (..., 3). |
| 174 | cameras (CamerasBase): pytorch3d cameras or mmhuman3d cameras. |
| 175 | resolution (Iterable[int]): (height, width) for rectangle or width for |
| 176 | square. |
| 177 | K (Union[torch.Tensor, np.ndarray], optional): intrinsic matrix. |
| 178 | Defaults to None. |
| 179 | R (Union[torch.Tensor, np.ndarray], optional): rotation matrix. |
| 180 | Defaults to None. |
| 181 | T (Union[torch.Tensor, np.ndarray], optional): translation matrix. |
| 182 | Defaults to None. |
| 183 | convention (str, optional): camera convention. Defaults to 'opencv'. |
| 184 | in_ndc (bool, optional): whether in NDC. Defaults to False. |
| 185 | |
| 186 | Returns: |
| 187 | Union[torch.Tensor, np.ndarray]: transformed points of shape (..., 2). |
| 188 | """ |
| 189 | if cameras is None: |
| 190 | cameras = build_cameras( |
| 191 | dict(type='perspective', |
| 192 | convention=convention, |
| 193 | in_ndc=in_ndc, |
| 194 | resolution=resolution, |
| 195 | K=K, |
| 196 | R=R, |
| 197 | T=T)) |
| 198 | if cameras.get_image_size() is not None: |
| 199 | image_size = cameras.get_image_size() |
| 200 | else: |
| 201 | image_size = resolution |
| 202 | if isinstance(points3d, np.ndarray): |
| 203 | points3d = torch.Tensor(points3d[..., :3]).to(cameras.device) |
| 204 | points2d = cameras.transform_points_screen( |
| 205 | points3d, image_size=image_size).cpu().numpy() |
| 206 | elif isinstance(points3d, torch.Tensor): |
| 207 | points3d = points3d[..., :3].to(cameras.device) |
| 208 | points2d = cameras.transform_points_screen(points3d, |
| 209 | image_size=image_size) |
| 210 | return points2d |
nothing calls this directly
no test coverage detected