paralleldomain.model.annotation.bounding_box_2d

class BoundingBox2D(x, y, width, height, class_id, instance_id, attributes=<factory>)

Represents a 2D Bounding Box annotation including geometry

Parameters:
x

Top-Left corner of bounding box in image pixels coordinates along x-axis

y

Top-Left corner of bounding box in image pixels coordinates along y-axis

width

Width of bounding box in pixels along x-axis

height

Height of bounding box in pixels along y-axis

class_id

Class ID of object annotated by bounding box.

instance_id

Instance ID of annotated object. Can be used to cross-reference with other instance annotation types, e.g., AnnotationTypes.InstanceSegmentation2D or AnnotationTypes.InstanceSegmentation3D.

attributes

Dictionary of arbitrary object attributes.

include_point(point, inline=False)

Extends the dimensions of the box to include the specified point.

Parameters:
  • point (Point2DBaseGeometry[TypeVar(T, int, float)]) – Instance of Point2DGeometry which needs to be included in updated bounding box.

  • inline (bool) – When set, do not return a copy of the object but update the current object. Default: False.

Return type:

Optional[BoundingBox2DBaseGeometry[TypeVar(T, int, float)]]

Returns:

A copy of the current object with extended dimensions, if inline is set. Otherwise, returns None.

include_points(points, inline=False)

Extends the dimensions of the box to include the specified point.

Parameters:
Return type:

Optional[BoundingBox2DBaseGeometry[TypeVar(T, int, float)]]

Returns:

A copy of the current object with extended dimensions, if inline is set. Otherwise, returns None.

classmethod merge_boxes(target_box, source_box)

Takes two 2D box geometries as input and merges both into a new box geometry. The resulting box geometry has dimensions from target_box and source_box merged into it.

Return type:

BoundingBox2DBaseGeometry[TypeVar(T, int, float)]

Parameters:
property area

Returns area of 2D Bounding Box in square pixel.

property edges: ndarray

Returns the 2D edges of a bounding box.

Edges are returned in order of connecting the vertices in the following order:

  • [0, 1]

  • [1, 2]

  • [2, 3]

  • [3, 0]

0--------1
|        |
|        | right
|        |
3--------2
  bottom
property vertices: ndarray

Returns the 2D vertices of a bounding box.

Vertices are returned in the following order:

0--------1
|        |
|        | right
|        |
3--------2
  bottom
property x_max: T

Returns the maximum x value of the corners of the 2D Bounding Box

property x_min: T

Returns the minimum x value of the corners of the 2D Bounding Box

property y_max: T

Returns the maximum y value of the corners of the 2D Bounding Box

property y_min: T

Returns the minimum y value of the corners of the 2D Bounding Box

class BoundingBoxes2D(boxes)

Collection of 2D Bounding Boxes

Parameters:

boxes (List[BoundingBox2D]) – BoundingBoxes2D.boxes

boxes

Unordered list of AnnotationTypes.BoundingBox2D

get_box_by_instance_id(instance_id)

Returns the box with matching instance ID.

Parameters:

instance_id (int) – Instance ID of box that should be returned.

Return type:

Optional[BoundingBox2D]

Returns:

Matching box instance. If none found, returns None.

get_boxes_by_attribute_key(attr_key)

Returns all boxes having a certain attribute, independent of value.

Parameters:

attr_key (str) – Name of attribute.

Return type:

List[BoundingBox2D]

Returns:

List of box instances that have the specified attribute.

get_boxes_by_attribute_value(attr_key, attr_value)

Returns all boxes having the specified attribute and value.

Parameters:
  • attr_key (str) – Name of attribute.

  • attr_value (Any) – Value of attribute.

Return type:

List[BoundingBox2D]

Returns:

List of box instances that have the specified attribute and value.

get_boxes_by_attribute_values(attr_key, attr_values)

Returns all boxes having the specified attribute and any of the values.

Parameters:
  • attr_key (str) – Name of attribute.

  • attr_values (List[Any]) – Allowed values of attribute.

Return type:

List[BoundingBox2D]

Returns:

List of box instances that have the specified attribute and any of the values.

get_boxes_by_class_id(class_id)

Returns all boxes having a the specified class ID.

Parameters:

class_id (int) – Class ID.

Return type:

List[BoundingBox2D]

Returns:

List of box instances that are of the specified class.

get_boxes_by_class_ids(class_ids)

Returns all boxes having any of the specified class IDs.

Parameters:

class_ids (List[int]) – Class IDs.

Return type:

List[BoundingBox2D]

Returns:

List of box instances that are of any of the specified classes.

static merge_boxes(target_box, source_box)

Merges a 2D Bounding Box into another 2D Bounding Box

Parameters:
  • target_box (BoundingBox2D) – The 2D Bounding Box into which source_box should be merged

  • source_box (BoundingBox2D) – The 2D Bounding Box which should be merged into target_box

Return type:

BoundingBox2D

2D Bounding Box containing the dimensions of both `target_box` and `source_box` with the attributes of

target_box

Return type:

BoundingBox2D

Parameters: