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).
| Field | Type | Description |
|---|---|---|
half_sizes | ArrayLike | Half-size of each box; shape (2,) or (N, 2), dtype float32. Required if arrays is not provided. |
centers | ArrayLike | Centers of each box; shape (2,) or (N, 2), dtype float32. Required if arrays is not provided. |
arrays | ArrayLike | Array of boxes shape (N, 4) in the format given by array_format, dtype float32. Use instead of half_sizes/centers. |
Optional
| Field | Type | Description |
|---|---|---|
array_format | str or Box2DFormat | How to interpret arrays. Default "XYWH". See Enums for all values. |
Methods
| Method | Description |
|---|---|
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"])
