# detection

Python API: `depthai_nodes.message.creators.detection`

## Functions

| Name | Description |
| --- | --- |
| [`create_detection_message`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/creators/detection.md#detection-Functions-create_detection_message) | Create native detections with optional keypoints and an instance mask. |

### function `create_detection_message`

```python
def create_detection_message(
    bboxes: np.ndarray,
    scores: np.ndarray,
    angles: np.ndarray | None = None,
    labels: np.ndarray | None = None,
    label_names: list[str] | None = None,
    keypoints: np.ndarray | None = None,
    keypoints_scores: np.ndarray | None = None,
    keypoint_label_names: list[str] | None = None,
    keypoint_edges: list[tuple[int, int]] | None = None,
    masks: np.ndarray | None = None,
) -> dai.ImgDetections
```

Create native detections with optional keypoints and an instance mask.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `bboxes` | `np.ndarray` | NumPy array of normalized `(N, 4)` center-XY/width/height boxes. An empty array returns an empty detection message immediately. | required |
| `scores` | `np.ndarray` | NumPy array of shape `(N,)` with detection confidences. | required |
| `angles` | `np.ndarray | None` | Optional angle per detection in degrees within [-360, 360]. | `None` |
| `labels` | `np.ndarray | None` | Optional NumPy array of class IDs, one per detection. Values are converted to integers. | `None` |
| `label_names` | `list[str] | None` | Optional names in detection order, one per detection. Names are assigned only when `labels` is supplied. This is not a class-ID lookup table. | `None` |
| `keypoints` | `np.ndarray | None` | Optional coordinates of shape `(N, K, 2)` or `(N, K, 3)`. Two-dimensional points receive Z=0. | `None` |
| `keypoints_scores` | `np.ndarray | None` | Optional floating-point confidences of shape `(N, K)` in [0, 1]; requires `keypoints`. | `None` |
| `keypoint_label_names` | `list[str] | None` | Optional list of keypoint names. Currently validated but not attached to the output keypoints. | `None` |
| `keypoint_edges` | `list[tuple[int, int]] | None` | Optional integer index pairs defining the skeleton for each detection. | `None` |
| `masks` | `np.ndarray | None` | Optional HW instance-ID mask, converted to uint8. IDs correspond to detection indexes; reserve 255 for background. Conversion does not validate representability. | `None` |

Returns

| Type | Description |
| --- | --- |
| `dai.ImgDetections` | Native detection message with the supplied payload. Caller sets timestamps, sequence number, and transformation. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If supplied arrays or optional metadata fail type, length, shape, or range checks. |
| `IndexError` | If a per-detection name or score array cannot be indexed as required. |
