dgp.utils.structures package

dgp.utils.structures.bounding_box_2d module

class dgp.utils.structures.bounding_box_2d.BoundingBox2D(box, class_id=1, instance_id=None, color=(0, 0, 0), attributes=None, mode='ltwh')

Bases: object

2D bounding box object.

box: np.ndarray[np.float32]

Array of 4 floats describing bounding box coordinates. Can be either ([l, t, r, b] or [l, t, w, h]).

class_id: int, default: GENERIC_OBJECT_CLASS

Integer class ID (0 reserved for background).

instance_id: int, default: None

Unique instance ID for bounding box. If None provided, the ID is a hash of the bounding box location and class.

color: tuple, default: (0, 0, 0)

RGB tuple for bounding box color

attributes: dict, default: None

Dictionary of attributes associated with bounding box. If None provided, defaults to empty dict.

mode: str, default: ltwh

One of “ltwh” or “ltrb”. Corresponds to “[left, top, width, height]” representation or “[left, top, right, bottom]”

Exception

Raised if the value of mode is unsupported.

property area
property attributes
property class_id
property color
property hexdigest
property instance_id
intersection_over_union(other)

Compute intersection over union of this box against other(s).

other: BoundingBox2D

A separate BoundingBox2D instance to compute IoU against.

NotImplementedError

Unconditionally

property ltrb
property ltwh
render(image)

Render bounding boxes on an image.

image: PIL.Image or np.ndarray

Background image on which boxes are rendered

image: PIL.Image or np.ndarray

Image with boxes rendered

to_proto()

Serialize bounding box to proto object.

NOTE: Does not serialize class or instance information, just box geometry. To serialize a complete annotation, see dgp/annotations/bounding_box_2d_annotation.py

BoundingBox2D.pb2

As defined in proto/annotations.proto

dgp.utils.structures.bounding_box_3d module

class dgp.utils.structures.bounding_box_3d.BoundingBox3D(pose, sizes=array([0., 0., 0.], dtype=float32), class_id=1, instance_id=None, color=(0, 0, 0), attributes=None, num_points=0, occlusion=0, truncation=0.0, feature_ontology_type=None, sample_idx=None)

Bases: object

3D bounding box (cuboid) that is centered at pose with extent sizes.

pose: dgp.utils.pose.Pose, (default: Pose())

Pose of the center of the 3D cuboid.

sizes: np.float32, (default: np.float32([0,0,0]))

Extents of the cuboid (width, length, height).

class_id: int, default: GENERIC_OBJECT_CLASS

Integer class ID (0 reserved for background).

instance_id: int, default: None

Unique instance ID for bounding box. If None provided, the ID is a hash of the bounding box location and class.

color: tuple, default: (0, 0, 0)

RGB tuple for bounding box color.

attributes: dict, default: None

Dictionary of attributes associated with bounding box. If None provided, defaults to empty dict.

num_points: int, default: 0

Number of LIDAR points associated with this bounding box.

occlusion: int, default: 0

Occlusion state (KITTI3D style).

truncation: float, default: 0

Fraction of truncation of object (KITTI3D style).

feature_ontology_type: dgp.proto.features.FeatureType

Type of feature of attributions.

sample_idx: int

index of sample in scene

property attributes
property class_id
property corners

Get 8 corners of the 3D bounding box. Note: The pose is oriented such that x-forward, y-left, z-up. This corresponds to L (length) along x, W (width) along y, and H (height) along z.

corners: np.ndarray (8 x 3)

Corners of the 3D bounding box.

property edges

Get the 12 edge links of the 3D bounding box, indexed by the corners defined by self.corners`.

edges: np.ndarray (12 x 2)

Edge links of the 3D bounding box.

property feature_ontology_type
property hexdigest
property instance_id
property num_points
property occlusion
property pose
render(image, camera, line_thickness=2, class_name=None, font_scale=0.5)

Render the bounding box on the image.

image: np.ndarray

Image (H, W, C) to render the bounding box onto. We assume the input image is in RGB format. The type must be uint8.

camera: dgp.utils.camera.Camera

Camera used to render the bounding box.

line_thickness: int, optional

Thickness of bounding box lines. Default: 2.

class_name: str, optional

Class name of the bounding box. Default: None.

font_scale: float, optional

Font scale used in text labels. Default: 0.5.

image: np.uint8 array

Rendered image (H, W, 3).

ValueError

Raised if image is not a 3-channel uint8 numpy array.

TypeError

Raised if camera is not an instance of Camera.

property sample_idx
property sizes
to_proto()

Serialize bounding box to proto object.

NOTE: Does not serialize class or instance information, just box properties. To serialize a complete annotation, see dgp/annotations/bounding_box_3d_annotation.py

BoundingBox3D.pb2

As defined in proto/annotations.proto.

property truncation
property vectorize

Get a np.ndarray of with 10 dimensions representing the 3D bounding box

box_3d: np.float32 array

Box with coordinates (pose.quat.qw, pose.quat.qx, pose.quat.qy, pose.quat.qz, pose.tvec.x, pose.tvec.y, pose.tvec.z, width, length, height).

dgp.utils.structures.instance_mask module

class dgp.utils.structures.instance_mask.InstanceMask2D(mask, class_id=1, instance_id=None, color=(0, 0, 0), attributes=None)

Bases: object

2D instance mask object.

mask: np.ndarray[bool, np.uint8, np.int64]

2D boolean array describiing instance mask.

class_id: int, default: GENERIC_OBJECT_CLASS

Integer class ID (0 reserved for background).

instance_id: int, default: None

Unique instance ID for instance mask. If None provided, the ID is a hash of the instance mask, location and class.

attributes: dict, default: None

Dictionary of attributes associated with instance mask. If None provided, defaults to empty dict.

property area

Compute intersection over union of this box against other(s).

property attributes
property bitmask
property class_id
property color
property hexdigest
property instance_id
intersection_over_union(other)

Compute intersection over union of this box against other(s).

other: InstanceMask2D

Another instance of InstanceMask2D to compute IoU against.

NotImplementedError

Unconditionally.

render(image)

Render instance masks on an image.

image: PIL.Image or np.ndarray

Background image on which boxes are rendered

image: PIL.Image or np.ndarray

Image with boxes rendered

property rle
class dgp.utils.structures.instance_mask.RLEMask(size, counts)

Bases: object

Container of RLE-encoded mask.

See https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/mask.py for RLE format.

size: list[int] or np.ndarray[int]

Height and width of mask.

counts: list[int]

Count-encoding of RLE format.

to_dict()

dgp.utils.structures.key_point_2d module

class dgp.utils.structures.key_point_2d.KeyPoint2D(point, class_id=1, instance_id=None, color=(0, 0, 0), attributes=None)

Bases: object

2D keypoint object.

point: np.ndarray[np.float32]

Array of 2 floats describing keypoint coordinates [x, y].

class_id: int, default: GENERIC_OBJECT_CLASS

Integer class ID (0 reserved for background).

instance_id: int, default: None

Unique instance ID for keypoint. If None provided, the ID is a hash of the keypoint location and class.

color: tuple, default: (0, 0, 0)

RGB tuple for keypoint color

attributes: dict, default: None

Dictionary of attributes associated with keypoint. If None provided, defaults to empty dict.

property attributes
property class_id
property color
property hexdigest
property instance_id
to_proto()

Serialize keypoint to proto object.

NOTE: Does not serialize class or instance information, just point geometry. To serialize a complete annotation, see dgp/annotations/key_point_2d_annotation.py

KeyPoint2D.pb2

As defined in proto/annotations.proto

property xy

Module contents