Skip to content

Boxes2D

Represents 2D axis-aligned bounding boxes, either as half-sizes and centers or as a single array in a specified format (e.g. XYWH, XYXY). This datatype is used for 2D detection, cropping, and geometry across the Telekinesis ecosystem.

Field

Required

Provide either (half_sizes and centers) or arrays (mutually exclusive).

FieldTypeDescription
half_sizesArrayLikeHalf-size of each box; shape (2,) or (N, 2), dtype float32. Required if arrays is not provided.
centersArrayLikeCenters of each box; shape (2,) or (N, 2), dtype float32. Required if arrays is not provided.
arraysArrayLikeArray of boxes shape (N, 4) in the format given by array_format, dtype float32. Use instead of half_sizes/centers.

Optional

FieldTypeDescription
array_formatstr or Box2DFormatHow to interpret arrays. Default "XYWH". See Enums for all values.

Methods

MethodDescription
to_dict()Returns a dictionary with keys: half_sizes, centers (or arrays if constructed from arrays), and optionally array_format. Values are the stored arrays or format string.

Example

From the datatypes examples:

python
from datatypes import datatypes
from loguru import logger

# ------------------------------------------------
# 1. Create Boxes2D instance
# ------------------------------------------------
boxes_2d = datatypes.Boxes2D(
    half_sizes=[[1, 2], [3, 4]],
    centers=[[0.0, 0.0], [1.0, 1.0]],
)

# ------------------------------------------------
# 2. Access data via to_dict
# ------------------------------------------------
data = boxes_2d.to_dict()
logger.info("Boxes2D to_dict half_sizes={}", data["half_sizes"])
logger.info("Boxes2D to_dict centers={}", data["centers"])