tensorbay.geometry.keypoint#

The implementation of the TensorBay 2D keypoint.

class tensorbay.geometry.keypoint.Keypoint2D(*args, **kwargs)[source]#

Bases: tensorbay.utility.user.UserSequence[float]

This class defines the concept of Keypoint2D.

Keypoint2D contains the information of 2D keypoint, such as the coordinates and visible status(optional).

Parameters
  • x – The x coordinate of the 2D keypoint.

  • y – The y coordinate of the 2D keypoint.

  • v

    The visible status(optional) of the 2D keypoint.

    Visible status can be “BINARY” or “TERNARY”:

    Visual Status

    v = 0

    v = 1

    v = 2

    BINARY

    invisible

    visible

    TERNARY

    invisible

    occluded

    visible

  • args (float) –

  • kwargs (float) –

Return type

tensorbay.geometry.vector._V2

Examples

Initialization Method 1: Init from coordinates of x, y.

>>> Keypoint2D(1.0, 2.0)
Keypoint2D(1.0, 2.0)

Initialization Method 2: Init from coordinates and visible status.

>>> Keypoint2D(1.0, 2.0, 0)
Keypoint2D(1.0, 2.0, 0)
classmethod loads(contents)[source]#

Load a Keypoint2D from a dict containing coordinates of a 2D keypoint.

Parameters

contents (Mapping[str, float]) – A dict containing coordinates and visible status(optional) of a 2D keypoint.

Returns

The loaded Keypoint2D object.

Return type

tensorbay.geometry.keypoint._T

Examples

>>> contents = {"x":1.0,"y":2.0,"v":1}
>>> Keypoint2D.loads(contents)
Keypoint2D(1.0, 2.0, 1)
property v: Optional[int]#

Return the visible status of the 2D keypoint.

Returns

Visible status of the 2D keypoint.

Examples

>>> keypoint = Keypoint2D(3.0, 2.0, 1)
>>> keypoint.v
1
dumps()[source]#

Dumps the Keypoint2D into a dict.

Returns

A dict containing coordinates and visible status(optional) of the 2D keypoint.

Return type

Dict[str, float]

Examples

>>> keypoint = Keypoint2D(1.0, 2.0, 1)
>>> keypoint.dumps()
{'x': 1.0, 'y': 2.0, 'v': 1}
class tensorbay.geometry.keypoint.Keypoints2D(points=None)[source]#

Bases: tensorbay.geometry.point_list.PointList2D[tensorbay.geometry.keypoint.Keypoint2D]

This class defines the concept of Keypoints2D.

Keypoints2D contains a list of 2D keypoint and is based on PointList2D.

Examples

>>> Keypoints2D([[1, 2], [2, 3]])
Keypoints2D [
  Keypoint2D(1, 2),
  Keypoint2D(2, 3)
]
classmethod loads(contents)[source]#

Load a Keypoints2D from a list of dict.

Parameters

contents (Sequence[Mapping[str, float]]) – A list of dictionaries containing 2D keypoint.

Returns

The loaded Keypoints2D object.

Return type

tensorbay.geometry.keypoint._P

Examples

>>> contents = [{"x": 1.0, "y": 1.0, "v": 1}, {"x": 2.0, "y": 2.0, "v": 2}]
>>> Keypoints2D.loads(contents)
Keypoints2D [
  Keypoint2D(1.0, 1.0, 1),
  Keypoint2D(2.0, 2.0, 2)
]