dataeval.utils.preprocessing.BoundingBox

class dataeval.utils.preprocessing.BoundingBox(v1, v2, v3, v4, *, bbox_format=BoundingBoxFormat.XYXY, image_shape=None)

A bounding box representation that supports multiple coordinate formats.

Parameters:
v1 : float

First coordinate value

v2 : float

Second coordinate value

v3 : float

Third coordinate value

v4 : float

Fourth coordinate value

bbox_format : BoundingBoxFormat, default BoundingBoxFormat.XYXY

Input format of the coordinates

image_shape : tuple[int, ...] or None, default None

Shape of the image in CHW format

Examples

Create a bounding box in XYXY format:

>>> bbox = BoundingBox(10, 20, 100, 150, bbox_format=BoundingBoxFormat.XYXY)
>>> bbox.xyxy
(10.0, 20.0, 100.0, 150.0)

Convert to different formats:

>>> bbox.xywh
(10.0, 20.0, 90.0, 130.0)
>>> bbox.cxcywh
(55.0, 85.0, 90.0, 130.0)

With image shape for YOLO format:

>>> bbox = BoundingBox(0.5, 0.5, 0.2, 0.3, bbox_format=BoundingBoxFormat.YOLO, image_shape=(3, 224, 224))
>>> bbox.xyxy
(89.6, 78.4, 134.4, 145.6)
area()

Calculate bounding box area.

center()

Get center coordinates (x, y).

is_clippable()

Check if bounding box can be clipped to image bounds.

is_inside()

Check if bounding box is within image bounds.

is_outside()

Check if bounding box is outside image bounds.

is_partial()

Check if bounding box is partially inside image bounds.

is_valid()

Check if bounding box is valid (not empty).

property cxcywh : tuple[float, float, float, float]

Get coordinates in CXCYWH format (center_x, center_y, width, height).

property height : float

Get bounding box height.

property image_hw : tuple[int, int]

Get image height and width.

property width : float

Get bounding box width.

property x0 : float

Get x0 coordinate.

property x1 : float

Get x1 coordinate.

property xywh : tuple[float, float, float, float]

Get coordinates in XYWH format (x, y, width, height).

property xyxy : tuple[float, float, float, float]

Get coordinates in XYXY format (x0, y0, x1, y1).

property xyxy_int : tuple[int, int, int, int]

Get coordinates in XYXY format as int (x0, y0, x1, y1).

property y0 : float

Get y0 coordinate.

property y1 : float

Get y1 coordinate.

property yolo : tuple[float, float, float, float]

Get coordinates in YOLO format (center_x, center_y, width, height) normalized to [0, 1].