kornia.geometry.keypoints#
Object-oriented API for keypoints: Keypoints wraps a tensor of 2D (x, y)
points and transforms and pads it; Keypoints3D validates and stores 3D
(x, y, z) points.
- class kornia.geometry.keypoints.Keypoints(keypoints, raise_if_not_floating_point=True)[source]#
2D keypoints, stored as an \((N, 2)\) or \((B, N, 2)\) tensor of
(x, y)points.- Parameters:
- Convention:
A point is
(x, y)in pixel coordinates (Coordinates and sizes), the frame of theBoxesvertices.transform_keypoints()maps a point to \(M [x, y, 1]^\top\) and converts it back withconvert_points_from_homogeneous().inplace=Falsereturns a newKeypoints;inplace=Trueandtransform_keypoints_()rebindselfto the transformed tensor and returnself. Neither writes into the tensor thatselfwrapped.The constructor and
from_tensor()wrap a floating-point tensor without copying it.pad(),unpad(), item assignment andindex_put(inplace=True)write into the stored tensor, so they change the caller’s tensor; callclone()first to keep it.Known defects: list input and
to_tensor(as_padded_sequence=True)raiseNotImplementedError(#5023).
- property data: Tensor#
Return the raw 2D keypoint coordinate tensor.
- Returns:
Tensor storing keypoint coordinates in
(..., 2)format, where the last dimension containsxandy.
- index_put(indices, values, inplace=False)[source]#
Write keypoint coordinates at selected tensor indices.
See the Convention block on
Keypoints.- Parameters:
indices (
Union[Tuple[Tensor,...],List[Tensor]]) – Index tuple or list accepted byTensor.index_put_for the stored coordinate tensor.values (
Union[Tensor,Keypoints]) – Replacement coordinates, either as a raw tensor or anotherKeypointsobject.inplace (
bool, optional) – IfTrue, update this object in place. Otherwise, clone the coordinates first and return a new wrapper. Default:False
- Return type:
- Returns:
Keypointsobject containing the updated coordinates.
- pad(padding_size)[source]#
Pad the keypoints in place.
See the Convention block on
Keypoints.padding_sizeis ordered as(left, right, top, bottom). Onlyleftandtopshift the coordinate origin. Both the batched \((B, N, 2)\) and the unbatched \((N, 2)\) container are supported; the unbatched form carries a single image, sopadding_sizemust have exactly one row.
- 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.
- transform_keypoints(M, inplace=False)[source]#
Apply a transformation matrix to the 2D keypoints.
See the Convention block on
Keypoints.- Parameters:
- Return type:
- Returns:
The transformed keypoints.
- transform_keypoints_(M)[source]#
Inplace version of
Keypoints.transform_keypoints().- Return type:
- class kornia.geometry.keypoints.Keypoints3D(keypoints, raise_if_not_floating_point=True)[source]#
3D keypoints, stored as an \((N, 3)\) or \((B, N, 3)\) tensor of
(x, y, z)points.The constructor validates the tensor as
Keypointsdoes and wraps a floating-point one without copying it.- Parameters:
- Convention:
Known defects: list input,
pad(),unpad(),transform_keypoints(),transform_keypoints_()andto_tensor(as_padded_sequence=True)raiseNotImplementedError(#5023).
- 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:
- Returns:
New
Keypoints3Dinstance containing the input coordinates.
- 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
Keypoints3Dto a tensor.
- transform_keypoints(M, inplace=False)[source]#
Not implemented: raises
NotImplementedError(#5023).Use
transform_points()ondatainstead.- Return type: