Perspective Camera#
- kornia.geometry.camera.perspective.project_points(point_3d, camera_matrix)[source]#
Project a 3d point onto the 2d camera plane.
See the Convention block on
PinholeCamera.- Convention:
point_3dis a camera-frame point andcamera_matrixthe \((*, 3, 3)\)K; the function takes no extrinsics, so it does not move between frames.the input must be at least rank 2: an unbatched \((3,)\) point raises
ValueError.
Warning
At
abs(z) <= 1e-8the divide is skipped andKis applied to the undivided point, giving the finite placeholderfx x + cx; the other projection entry points do not follow this rule yet: #4267. Neither that placeholder nor a point behind the camera is flagged as invalid: #4555.- Parameters:
- Return type:
- Returns:
tensor of (u, v) cam coordinates with shape \((*, 2)\).
Example
>>> _ = torch.manual_seed(0) >>> X = torch.rand(1, 3) >>> K = torch.eye(3)[None] >>> project_points(X, K) tensor([[5.6088, 8.6827]])
- kornia.geometry.camera.perspective.unproject_points(point_2d, depth, camera_matrix, normalize=False)[source]#
Unproject a 2d point in 3d.
Transform coordinates in the pixel frame to the camera frame.
See the Convention block on
PinholeCamera.- Convention:
point_2dis a pixel coordinate and the result is in the camera frame: the function takes no extrinsics, so it cannot return world coordinates.unproject()is the world-frame counterpart.depthis the camera-framezof the result. Withnormalize=Trueit is read as the Euclidean ray length instead, so the result has that norm and a smallerz.
- Parameters:
point_2d (
Tensor) – tensor containing the 2d points to be projected to the camera frame. The shape of the tensor can be \((*, 2)\).depth (
Tensor) – tensor containing the depth value of each 2d points. The tensor shape must be equal to point2d \((*, 1)\).camera_matrix (
Tensor) – tensor containing the intrinsics camera matrix. The tensor shape must be \((*, 3, 3)\).normalize (
bool, optional) – whether to normalize the pointcloud. This must be set to True when the depth is represented as the Euclidean ray length from the camera position. Default:False
- Return type:
- Returns:
tensor of (x, y, z) camera coordinates with shape \((*, 3)\).
Example
>>> _ = torch.manual_seed(0) >>> x = torch.rand(1, 2) >>> depth = torch.ones(1, 1) >>> K = torch.eye(3)[None] >>> unproject_points(x, depth, K) tensor([[0.4963, 0.7682, 1.0000]])