kornia.geometry.keypoints

Module with useful functionalities for 2D and 3D keypoints manipulation.

class kornia.geometry.keypoints.Keypoints(keypoints, raise_if_not_floating_point=True)[source]

2D Keypoints containing Nx2 or BxNx2 points.

Parameters:
  • keypoints (Union[Tensor, List[Tensor]]) – Raw tensor or a list of torch.Tensors with the Nx2 coordinates

  • raise_if_not_floating_point (bool, optional) – will raise if the torch.Tensor isn’t float Default: True

clone()[source]

Create an independent copy of the 2D keypoints.

Return type:

Keypoints

property data: Tensor

Return the raw 2D keypoint coordinate tensor.

Returns:

Tensor storing keypoint coordinates in (..., 2) format, where the last dimension contains x and y.

property device: device

Returns keypoints device.

property dtype: dtype

Returns keypoints dtype.

classmethod from_tensor(keypoints)[source]

Validate and wrap a tensor of 2D keypoint coordinates.

Parameters:

keypoints (Tensor) – Tensor in \((N, 2)\) or \((B, N, 2)\) format. The last dimension stores (x, y) coordinates.

Return type:

Keypoints

Returns:

New Keypoints instance containing the input coordinates.

index_put(indices, values, inplace=False)[source]

Write keypoint coordinates at selected tensor indices.

Parameters:
  • indices (Union[Tuple[Tensor, ...], List[Tensor]]) – Index tuple or list accepted by Tensor.index_put_ for the stored coordinate tensor.

  • values (Union[Tensor, Keypoints]) – Replacement coordinates, either as a raw tensor or another Keypoints object.

  • inplace (bool, optional) – If True, update this object in place. Otherwise, clone the coordinates first and return a new wrapper. Default: False

Return type:

Keypoints

Returns:

Keypoints object containing the updated coordinates.

pad(padding_size)[source]

Pad a bounding keypoints.

Parameters:

padding_size (Tensor) – (B, 4)

Return type:

Keypoints

property shape: Tuple[int, ...] | Size

Return the tensor shape used to store 2D keypoints.

Returns:

Shape of data. The common layouts are \((N, 2)\) for unbatched keypoints and \((B, N, 2)\) for batched keypoints, where \(B\) is the batch size, \(N\) is the number of keypoints, and the final dimension stores (x, y) coordinates.

to_tensor(as_padded_sequence=False)[source]

Cast Keypoints to a tensor.

mode controls which 2D keypoints format should be use to represent keypoints in the tensor.

Parameters:

as_padded_sequence (bool, optional) – whether to keep the pads for a list of keypoints. This parameter is only valid if the keypoints are from a keypoint list. Default: False

Return type:

Union[Tensor, List[Tensor]]

Returns:

Keypoints tensor \((B, N, 2)\)

transform_keypoints(M, inplace=False)[source]

Apply a transformation matrix to the 2D keypoints.

Parameters:
  • M (Tensor) – The transformation matrix to be applied, shape of \((3, 3)\) or \((B, 3, 3)\).

  • inplace (bool, optional) – do transform in-place and return self. Default: False

Return type:

Keypoints

Returns:

The transformed keypoints.

transform_keypoints_(M)[source]

Inplace version of Keypoints.transform_keypoints().

Return type:

Keypoints

type(dtype)[source]

Cast stored keypoint coordinates to a target dtype.

Parameters:

dtype (dtype) – Destination floating-point dtype for the coordinate tensor.

Return type:

Keypoints

Returns:

self after converting the stored coordinates in place.

unpad(padding_size)[source]

Pad a bounding keypoints.

Parameters:

padding_size (Tensor) – (B, 4)

Return type:

Keypoints

class kornia.geometry.keypoints.Keypoints3D(keypoints, raise_if_not_floating_point=True)[source]

3D Keypoints containing Nx3 or BxNx3 points.

Parameters:
  • keypoints (Union[Tensor, List[Tensor]]) – Raw tensor or a list of torch.Tensors with the Nx3 coordinates

  • raise_if_not_floating_point (bool, optional) – will raise if the torch.Tensor isn’t float Default: True

clone()[source]

Create an independent copy of the 3D keypoints.

Return type:

Keypoints3D

property data: Tensor

Return the raw 3D keypoint coordinate tensor.

Returns:

Tensor storing coordinates in (..., 3) format, with the final dimension ordered as (x, y, z).

classmethod from_tensor(keypoints)[source]

Validate and wrap a tensor of 3D keypoint coordinates.

Parameters:

keypoints (Tensor) – Tensor in \((N, 3)\) or \((B, N, 3)\) format, where the last dimension stores (x, y, z).

Return type:

Keypoints3D

Returns:

New Keypoints3D instance containing the input coordinates.

pad(padding_size)[source]

Pad a bounding keypoints.

Parameters:

padding_size (Tensor) – (B, 6)

Return type:

Keypoints3D

property shape: Size

Return the tensor shape used to store 3D keypoints.

Returns:

Shape of data. The common layouts are \((N, 3)\) and \((B, N, 3)\), where the final dimension stores (x, y, z) coordinates.

to_tensor(as_padded_sequence=False)[source]

Cast Keypoints to a tensor.

mode controls which 2D keypoints format should be use to represent keypoints in the tensor.

Parameters:

as_padded_sequence (bool, optional) – whether to keep the pads for a list of keypoints. This parameter is only valid if the keypoints are from a keypoint list. Default: False

Return type:

Union[Tensor, List[Tensor]]

Returns:

Keypoints tensor \((B, N, 3)\)

transform_keypoints(M, inplace=False)[source]

Apply a transformation matrix to the 2D keypoints.

Parameters:
  • M (Tensor) – The transformation matrix to be applied, shape of \((3, 3)\) or \((B, 3, 3)\).

  • inplace (bool, optional) – do transform in-place and return self. Default: False

Return type:

Keypoints3D

Returns:

The transformed keypoints.

transform_keypoints_(M)[source]

Inplace version of Keypoints.transform_keypoints().

Return type:

Keypoints3D

unpad(padding_size)[source]

Pad a bounding keypoints.

Parameters:

padding_size (Tensor) – (B, 6)

Return type:

Keypoints3D