Perspective Camera

kornia.geometry.camera.perspective.project_points(point_3d, camera_matrix)

Project a 3d point onto the 2d camera plane.

Parameters:
  • point3d – tensor containing the 3d points to be projected to the camera plane. The shape of the tensor can be \((*, 3)\).

  • camera_matrix (Tensor) – tensor containing the intrinsics camera matrix. The tensor shape must be \((*, 3, 3)\).

Return type:

Tensor

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)

Unproject a 2d point in 3d.

Transform coordinates in the pixel frame to the camera frame.

Parameters:
  • point2d – tensor containing the 2d to be projected to world coordinates. 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:

Tensor

Returns:

tensor of (x, y, z) world 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]])