Skip to content

dataclass

SemanticLabel

A dataclass to represent semantic labels.

Attributes:

  • name (str) –

    Label name.

  • attributes (list[str]) –

    List of attribute names.

Box3D

A class to represent 3D box.

Attributes:

  • unix_time (int) –

    Unix timestamp.

  • frame_id (str) –

    Coordinates frame ID where the box is with respect to.

  • semantic_label (SemanticLabel) –

    SemanticLabel object.

  • confidence (float) –

    Confidence score of the box.

  • uuid (str | None) –

    Unique box identifier.

  • position (Vector3Like) –

    Box center position (x, y, z).

  • rotation (QuaternionLike) –

    Box rotation quaternion.

  • shape (Shape) –

    Shape object.

  • velocity (Vector3Like | None) –

    Box velocity (vx, vy, vz).

  • num_points (int | None) –

    The number of points inside the box.

  • future (Future | None) –

    Box trajectory in the future of each mode.

Examples:

>>> # without future
>>> box3d = Box3D(
...     unix_time=100,
...     frame_id="base_link",
...     semantic_label=SemanticLabel("car"),
...     position=(1.0, 1.0, 1.0),
...     rotation=Quaternion([0.0, 0.0, 0.0, 1.0]),
...     shape=Shape(shape_type=ShapeType.BOUNDING_BOX, size=(1.0, 1.0, 1.0)),
...     velocity=(1.0, 1.0, 1.0),
...     confidence=1.0,
...     uuid="car3d_0",
... )
>>> # with future
>>> box3d = box3d.with_future(
...     waypoints=[[[1.0, 1.0, 1.0], [2.0, 2.0, 2.0], [3.0, 3.0, 3.0]]],
...     confidences=[1.0],
... )

size property

size: Vector3Like

Return the box size in the order of (width, length, height).

Returns:

  • Vector3Like

    (width, length, height) values.

with_future

with_future(
    timestamps: ArrayLike,
    confidences: ArrayLike,
    waypoints: ArrayLike,
) -> Self

Return a self instance setting future attribute.

Parameters:

  • timestamps
    (ArrayLike) –

    Array of future timestamps at each waypoint in the shape of (T).

  • confidences
    (ArrayLike) –

    Array of confidences for each mode in the shape of (M).

  • waypoints
    (ArrayLike) –

    Array of waypoints for each mode in the shape of (M, T, D).

Returns:

  • Self

    Self instance after setting future.

translate

translate(x: Vector3Like) -> None

Apply a translation.

Parameters:

  • x
    (Vector3Like) –

    3D translation vector in the order of (x, y, z).

rotate

rotate(q: QuaternionLike) -> None

Apply a rotation.

Parameters:

  • q
    (QuaternionLike) –

    Rotation quaternion.

corners

corners(box_scale: float = 1.0) -> NDArrayF64

Return the bounding box corners.

Parameters:

  • box_scale
    (float, default: 1.0 ) –

    Multiply size by this factor to scale the box.

Returns:

  • NDArrayF64

    First four corners are the ones facing forward. The last four are the ones facing backwards, in the shape of (8, 3).

Box2D

A class to represent 2D box.

Attributes:

  • unix_time (int) –

    Unix timestamp.

  • frame_id (str) –

    Coordinates frame ID where the box is with respect to.

  • semantic_label (SemanticLabel) –

    SemanticLabel object.

  • confidence (float) –

    Confidence score of the box.

  • uuid (str | None) –

    Unique box identifier.

  • roi (Roi | None) –

    Roi object.

  • position (Vector3Like | None) –

    3D position (x, y, z).

Examples:

>>> # without 3D position
>>> box2d = Box2D(
...     unix_time=100,
...     frame_id="camera",
...     semantic_label=SemanticLabel("car"),
...     roi=(100, 100, 50, 50),
...     confidence=1.0,
...     uuid="car2d_0",
... )
>>> # with 3D position
>>> box2d = box2d.with_position(position=(1.0, 1.0, 1.0))

with_position

with_position(position: Vector3Like) -> Self

Return a self instance setting position attribute.

Parameters:

  • position
    (Vector3Like) –

    3D position.

Returns:

  • Self

    Self instance after setting position.

distance_box

distance_box(
    box: BoxLike, tf_matrix: HomogeneousMatrix
) -> float | None

Return a box distance from base_link.

Parameters:

Raises:

  • TypeError

    Expecting type of box is Box2D or Box3D.

Returns:

  • float | None

    float | None: Return None if the type of box is Box2D and its position is None, otherwise returns distance from base_link.

PointCloud

Abstract base dataclass for pointcloud data.

num_dims abstractmethod staticmethod

num_dims() -> int

Return the number of the point dimensions.

Returns:

  • int ( int ) –

    The number of the point dimensions.

from_file abstractmethod classmethod

from_file(filepath: str) -> Self

Create an object from pointcloud file.

Parameters:

  • filepath
    (str) –

    File path of the pointcloud file.

Returns:

  • Self

    Self instance.

num_points

num_points() -> int

Return the number of points.

Returns:

  • int ( int ) –

    description

LidarPointCloud

A dataclass to represent lidar pointcloud.

Attributes:

  • points (NDArrayFloat) –

    Points matrix in the shape of (4, N).

RadarPointCloud

A dataclass to represent radar pointcloud.

Attributes:

  • points (NDArrayFloat) –

    Points matrix in the shape of (18, N).

SegmentationPointCloud

A dataclass to represent segmentation pointcloud.

Attributes:

  • points (NDArrayFloat) –

    Points matrix in the shape of (4, N).

  • labels (NDArrayU8) –

    Label matrix.

Roi

A dataclass to represent 2D box ROI.

Attributes:

  • roi (RoiLike) –

    Box ROI in the order of (xmin, ymin, xmax, ymax).

offset property

offset: tuple[int, int]

Return the xy offset from the image origin at the top left of the box.

Returns:

size property

size: tuple[int, int]

Return the size of the box.

Returns:

width property

width: int

Return the width of the box.

Returns:

  • int

    Box width.

height property

height: int

Return the height of the box.

Returns:

  • int

    Box height.

center property

center: tuple[int, int]

Return the center position of the box from the image origin.

Returns:

  • tuple[int, int]

    Center position of the box (cx, cy).

area property

area: int

Return the area of the box.

Returns:

  • int

    Area of the box.

ShapeType

Bases: Enum

from_name classmethod

from_name(name: str) -> Self

Return an enum object from the name of the member.

Parameters:

  • name
    (str) –

    Name of enum member.

Returns:

  • Self

    Enum object.

Shape

A dataclass to represent the 3D box shape.

Attributes:

  • shape_type (ShapeType) –

    Box shape type.

  • size (Vector3Like) –

    Box size in the order of (width, length, height).

  • footprint (Polygon) –

    Polygon of footprint.

Examples:

>>> shape = Shape(
...     shape_type=ShapeType.BOUNDING_BOX,
...     size=[1.0, 1.0, 1.0]
... )

Trajectory

A dataclass to represent trajectory.

Attributes:

  • waypoints (TrajectoryType) –

    Waypoints matrix in the shape of (N, 3).

  • confidence (float) –

    Confidence score the trajectory.

Examples:

>>> trajectory = Trajectory(
...     timestamps=[1.0, 2.0]
...     confidences=[1.0],
...     waypoints=[[[1.0, 1.0, 1.0], [2.0, 2.0, 2.0]]],
... )
# Get the number of modes.
>>> len(trajectory)
1
# Access the shape of waypoints matrix: (M, T, 3).
>>> trajectory.shape
(1, 2, 3)
# Access waypoints as subscriptable.
>>> trajectory[0] # for mode0
array([[1., 1., 1.],
       [2., 2., 2.]])
>>> trajectory[0, 0] # point0 at mode0
array([1., 1., 1.])
# Access confidence and waypoints for each mode as iterable.
>>> for i, (confidence, waypoints) in trajectory:
...     print(f"Mode{i}: {confidence}, {waypoints}")
...
Mode0: 1.0, [[1. 1. 1.] [2. 2. 2.]]

num_mode property

num_mode: int

Return the number of trajectory modes.

Returns:

  • int ( int ) –

    The number of trajectory modes.

num_timestamp property

num_timestamp: int

Return the number of timestamps.

Returns:

  • int ( int ) –

    The number of timestamps.

shape property

shape: tuple[int, ...]

Return the shape of the waypoints matrix.

Returns:

  • tuple[int, ...]

    Shape of the matrix (M, T, D).

translate

translate(x: Vector3Like) -> None

Apply a translation.

Parameters:

  • x
    (Vector3Like) –

    3D translation vector.

rotate

rotate(q: QuaternionLike) -> None

Apply a rotation.

Parameters:

  • q
    (QuaternionLike) –

    Rotation quaternion.

Past

Bases: Trajectory

Represent the past trajectory features.

Note that the expected shape of waypoints is (1, T, D).

Future

Bases: Trajectory

Represent the future trajectory features.

Note that the expected shape of waypoints is (M, T, D).

TransformBuffer

A buffer class to store transformation matrices.

Attributes:

set_transform

set_transform(matrix: HomogeneousMatrix) -> None

Set transform matrix to the buffer. Also, if its inverse transformation has not been registered, registers it too.

Parameters:

lookup_transform

lookup_transform(
    src: str, dst: str
) -> HomogeneousMatrix | None

Look up the transform matrix corresponding to the src and dst frame ID.

Parameters:

  • src
    (str) –

    Source frame ID.

  • dst
    (str) –

    Destination frame ID.

Returns:

  • HomogeneousMatrix | None

    Returns HomogeneousMatrix if the corresponding matrix can be found, otherwise it returns None.

do_translate

do_translate(
    src: str, dst: str, *args, **kwargs
) -> TranslateItemLike | None

Translate specified items with the matrix corresponding to src and dst frame ID.

Parameters:

  • src
    (str) –

    Source frame ID.

  • dst
    (str) –

    Destination frame ID.

Returns:

  • TranslateItemLike | None

    TranslateItemLike | None: Returns translated items if the corresponding matrix can be found, otherwise it returns None.

do_rotate

do_rotate(
    src: str, dst: str, *args, **kwargs
) -> RotateItemLike | None

Rotate specified items with the matrix corresponding to src and dst frame ID.

Parameters:

  • src
    (str) –

    Source frame ID.

  • dst
    (str) –

    Destination frame ID.

Returns:

  • RotateItemLike | None

    TranslateItemLike | None: Returns rotated items if the corresponding matrix can be found, otherwise it returns None.

do_transform

do_transform(
    src: str, dst: str, *args, **kwargs
) -> TransformItemLike | None

Transform specified items with the matrix corresponding to src and dst frame ID.

Parameters:

  • src
    (str) –

    Source frame ID.

  • dst
    (str) –

    Destination frame ID.

Returns:

  • TransformItemLike | None

    TranslateItemLike | None: Returns transformed items if the corresponding matrix can be found, otherwise it returns None.

HomogeneousMatrix

shape property

shape: tuple[int, ...]

Return a shape of the homogeneous matrix.

Returns:

  • tuple[int, ...]

    Return the shape of (4, 4).

yaw_pitch_roll property

yaw_pitch_roll: tuple[float, float, float]

Return yaw, pitch and roll.

NOTE

yaw: Rotation angle around the z-axis in [rad], in the range [-pi, pi]. pitch: Rotation angle around the y'-axis in [rad], in the range [-pi/2, pi/2]. roll: Rotation angle around the x"-axis in [rad], in the range [-pi, pi].

Returns:

rotation_matrix property

rotation_matrix: NDArray

Return a 3x3 rotation matrix.

Returns:

  • NDArray

    3x3 rotation matrix.

as_identity classmethod

as_identity(frame_id: str) -> Self

Construct a new object with identity.

Parameters:

  • frame_id
    (str) –

    Frame ID.

Returns:

  • Self

    Constructed self instance.

from_matrix classmethod

from_matrix(
    matrix: NDArray | HomogeneousMatrix,
    src: str | None = None,
    dst: str | None = None,
) -> Self

Construct a new object from a homogeneous matrix.

Parameters:

  • matrix
    (NDArray | HomogeneousMatrix) –

    4x4 homogeneous matrix.

  • src
    (str | None, default: None ) –

    Source frame ID. This must be specified only if the input matrix is NDArray.

  • dst
    (str | None, default: None ) –

    Destination frame ID. This must be specified only if the input matrix is NDArray.

Returns:

  • Self

    Constructed self instance.

dot

dot(other: HomogeneousMatrix) -> HomogeneousMatrix

Return a dot product of myself and another.

Parameters:

Raises:

  • ValueError

    self.src and other.dst must be the same frame ID.

Returns:

inv

inv() -> HomogeneousMatrix

Return a inverse matrix of myself.

Returns: