# segmentation_matching

Python API: `depthai_nodes.node.box_detector.segmentation_matching`

Pair tracked boxes with the detections whose instance masks they own.

## Functions

| Name | Description |
| --- | --- |
| [`intersection_over_union`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/box_detector/segmentation_matching.md#segmentation_matching-Functions-intersection_over_union) | Return the IoU of two `(xmin, ymin, xmax, ymax)` boxes. |
| [`match_tracklets_to_detections`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/box_detector/segmentation_matching.md#segmentation_matching-Functions-match_tracklets_to_detections) | Greedily pair tracklets and detections by descending IoU. |

### function `intersection_over_union`

```python
def intersection_over_union(a: Corners, b: Corners) -> float
```

Return the IoU of two `(xmin, ymin, xmax, ymax)` boxes.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `a` | `Corners` | First box. | required |
| `b` | `Corners` | Second box. | required |

Returns

| Type | Description |
| --- | --- |
| `float` | IoU in `[0, 1]`; zero when the boxes do not overlap. |

### function `match_tracklets_to_detections`

```python
def match_tracklets_to_detections(
    tracklets: list[dai.Tracklet],
    detections: list[dai.ImgDetection],
) -> dict[int, int]
```

Greedily pair tracklets and detections by descending IoU.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `tracklets` | `list[dai.Tracklet]` | Tracklets with normalized ROIs. | required |
| `detections` | `list[dai.ImgDetection]` | Detections with normalized corners. | required |

Returns

| Type | Description |
| --- | --- |
| `dict[int, int]` | Mapping of tracklet index to detection index. Pairs need a positive IoU, and each tracklet and detection appears at most once. |

## Module Attributes

| Name | Description |
| --- | --- |
| [`Corners`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/box_detector/segmentation_matching.md#segmentation_matching-Module-Attributes-Corners) |  |

### type alias `Corners`

```python
Corners = tuple[float, float, float, float]
```
