# box_detections

Python API: `depthai_nodes.message.box_detections`

Per-frame box detections, before any measurement.

## Classes

| Name | Description |
| --- | --- |
| [`BoxDetection`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Classes-BoxDetection) | A tracked box's identity and location in one processed frame. |
| [`BoxDetections`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Classes-BoxDetections) | Box detections sharing one segmentation label mask. |

### class `BoxDetection`

```python
class BoxDetection
```

A tracked box's identity and location in one processed frame.

Its segmentation is the region of the owning
[BoxDetections](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Classes-BoxDetections)
mask labelled with this item's index.

Raises

| Type | Description |
| --- | --- |
| `TypeError` | If a field has the wrong type. |
| `ValueError` | If `confidence` is not finite. |

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `bounding_box` | `dai.RotatedRect` | Normalized bounding box in the source frame. |
| `confidence` | `float` | Detection confidence. |
| `track_id` | `int` | Tracker ID of the box. |
| `track_status` | `dai.Tracklet.TrackingStatus` | Tracking status of the box in this frame, `NEW` or `TRACKED`. Lost tracks keep only their last-seen box, so they are not emitted. |

### class `BoxDetections`

```python
class BoxDetections(Collection)
```

Box detections sharing one segmentation label mask.

The mask covers the whole source frame, stretched to its own resolution. A pixel value is the index of the item it belongs to; 255
is background.

At most `MAX_DETECTIONS` (255) items fit, since label 255 is background. The mask is checked against the items only at
construction. Assigning `items`, `append()` and `extend()` do not recheck it.

Args

| Name | Description |
| --- | --- |
| `items` | Detections, indexed by the mask labels. |
| `segmentation_mask` | 2-D `uint8` label mask. |

Raises

| Type | Description |
| --- | --- |
| `TypeError` | If `segmentation_mask` is not a numpy array, or `items` is not a list of one type. |
| `ValueError` | If `segmentation_mask` is not a 2-D `uint8` array, a label does not index an item, or there are more than `MAX_DETECTIONS` items. |

Properties

| Name | Type | Description |
| --- | --- | --- |
| [`items`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Classes-BoxDetections-items) | `list[BoxDetection]` | The detections, indexed by the mask labels. |
| [`segmentation_mask`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Classes-BoxDetections-segmentation_mask) | `np.ndarray` | The shared `uint8` label mask; 255 marks background. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Classes-BoxDetections-__init__) | Initialize the detections and check the mask against them. |
| [`append`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Classes-BoxDetections-append) | Append one detection. |
| [`getMask`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Classes-BoxDetections-getMask) | Return the segmentation mask of one detection. |
| [`getVisualizationMessage`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Classes-BoxDetections-getVisualizationMessage) | Outline each box, labelled with its track ID and confidence. |
| [`items.setter`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Classes-BoxDetections-items.setter) | Replace the detections after checking their count and types. |

#### property `items`

```python
items: list[BoxDetection]
```

The detections, indexed by the mask labels.

#### property `segmentation_mask`

```python
segmentation_mask: np.ndarray
```

The shared `uint8` label mask; 255 marks background.

#### method `__init__`

```python
def __init__(items: list[BoxDetection], segmentation_mask: np.ndarray)
```

Initialize the detections and check the mask against them.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `items` | `list[BoxDetection]` | Detections, indexed by the mask labels. | required |
| `segmentation_mask` | `np.ndarray` | 2-D `uint8` label mask; 255 is background. | required |

Raises

| Type | Description |
| --- | --- |
| `TypeError` | If `segmentation_mask` is not a numpy array, or `items` is not a list of one type. |
| `ValueError` | If `segmentation_mask` is not a 2-D `uint8` array, a label does not index an item, or there are more than `MAX_DETECTIONS` items. |

#### method `append`

```python
def append(item: BoxDetection)
```

Append one detection.

Raises

| Type | Description |
| --- | --- |
| `TypeError` | If the item is not a `BoxDetection`. |
| `ValueError` | If the collection already holds `MAX_DETECTIONS` items. |

#### method `getMask`

```python
def getMask(index: int) -> np.ndarray
```

Return the segmentation mask of one detection.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `index` | `int` | Index of the detection in `items`. | required |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Boolean mask, `True` where the pixel belongs to the detection. |

Raises

| Type | Description |
| --- | --- |
| `IndexError` | If `index` is outside `items`. |

#### method `getVisualizationMessage`

```python
def getVisualizationMessage() -> dai.ImgAnnotations
```

Outline each box, labelled with its track ID and confidence.

Returns

| Type | Description |
| --- | --- |
| `dai.ImgAnnotations` | Annotations with this message's buffer metadata. |

#### method `items.setter`

```python
def items.setter(value: list[BoxDetection])
```

Replace the detections after checking their count and types.

Raises

| Type | Description |
| --- | --- |
| `TypeError` | If the value is not a list of one type. |
| `ValueError` | If there are more than `MAX_DETECTIONS` items. |

## Module Attributes

| Name | Type | Description |
| --- | --- | --- |
| [`BACKGROUND_LABEL`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/box_detections.md#box_detections-Module-Attributes-BACKGROUND_LABEL) | `int` |  |

### constant `BACKGROUND_LABEL`

```python
BACKGROUND_LABEL: int = 255
```
