# annotation_helper

Python API: `depthai_nodes.utils.annotation_helper`

## Classes

| Name | Description |
| --- | --- |
| [`AnnotationHelper`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Classes-AnnotationHelper) | Simplifies `dai.ImgAnnotation` creation. |

### class `AnnotationHelper`

```python
class AnnotationHelper
```

Simplifies `dai.ImgAnnotation` creation.

After calling the desired drawing methods, call the `build` method to create the `ImgAnnotations` message.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `annotation` | `dai.ImgAnnotation` |  |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Classes-AnnotationHelper-__init__) | Create an empty annotation builder. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Classes-AnnotationHelper-build) | Creates an ImgAnnotations message. |
| [`draw_circle`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Classes-AnnotationHelper-draw_circle) | Draws a circle. |
| [`draw_line`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Classes-AnnotationHelper-draw_line) | Draws a line between two points. |
| [`draw_points`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Classes-AnnotationHelper-draw_points) | Draws points. |
| [`draw_polyline`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Classes-AnnotationHelper-draw_polyline) | Draws a polyline. |
| [`draw_rectangle`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Classes-AnnotationHelper-draw_rectangle) | Draws a rectangle. |
| [`draw_rotated_rect`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Classes-AnnotationHelper-draw_rotated_rect) | Draws a rotated rectangle. |
| [`draw_text`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Classes-AnnotationHelper-draw_text) | Draws text. |

#### method `__init__`

```python
def __init__(viewport_clipper: ViewportClipper | None = None)
```

Create an empty annotation builder.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `viewport_clipper` | `ViewportClipper | None` | Optional clipping bounds. Defaults to the normalized unit viewport [0, 1] on both axes. | `None` |

#### method `build`

```python
def build(timestamp: timedelta, sequence_num: int) -> dai.ImgAnnotations
```

Creates an ImgAnnotations message.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `timestamp` | `timedelta` | Message timestamp | required |
| `sequence_num` | `int` | Message sequence number | required |

Returns

| Type | Description |
| --- | --- |
| `dai.ImgAnnotations` | Created ImgAnnotations message |

#### method `draw_circle`

```python
def draw_circle(
    center: Point | dai.Point2f,
    radius: float,
    outline_color: ColorRGBA | dai.Color = PRIMARY_COLOR,
    fill_color: ColorRGBA | None | dai.Color | None = None,
    thickness: float = 1.0,
) -> AnnotationHelper
```

Draws a circle.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `center` | `Point | dai.Point2f` | Center of the circle | required |
| `radius` | `float` | Radius of the circle | required |
| `outline_color` | `ColorRGBA | dai.Color` | Outline color | `PRIMARY_COLOR` |
| `fill_color` | `ColorRGBA | None | dai.Color | None` | Fill color (None for no fill) | `None` |
| `thickness` | `float` | Outline thickness | `1.0` |

Returns

| Type | Description |
| --- | --- |
| `AnnotationHelper` | self |

#### method `draw_line`

```python
def draw_line(
    pt1: Point | dai.Point2f,
    pt2: Point | dai.Point2f,
    color: ColorRGBA | dai.Color = PRIMARY_COLOR,
    thickness: float = 2.0,
    clip_to_viewport: bool = False,
) -> AnnotationHelper
```

Draws a line between two points.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `pt1` | `Point | dai.Point2f` | Start of the line | required |
| `pt2` | `Point | dai.Point2f` | End of the line | required |
| `color` | `ColorRGBA | dai.Color` | Line color | `PRIMARY_COLOR` |
| `thickness` | `float` | Line thickness | `2.0` |
| `clip_to_viewport` | `bool` | Indication whether to clip the line to the viewport | `False` |

Returns

| Type | Description |
| --- | --- |
| `AnnotationHelper` | self |

#### method `draw_points`

```python
def draw_points(
    points: list[Point] | list[dai.Point2f] | dai.VectorPoint2f,
    color: ColorRGBA | dai.Color = PRIMARY_COLOR,
    thickness: float = 2.0,
) -> AnnotationHelper
```

Draws points.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `points` | `list[Point] | list[dai.Point2f] | dai.VectorPoint2f` | List of points to draw | required |
| `color` | `ColorRGBA | dai.Color` | Color of the points | `PRIMARY_COLOR` |
| `thickness` | `float` | Size of the points | `2.0` |

Returns

| Type | Description |
| --- | --- |
| `AnnotationHelper` | self |

#### method `draw_polyline`

```python
def draw_polyline(
    points: list[Point] | list[dai.Point2f],
    outline_color: ColorRGBA | dai.Color = PRIMARY_COLOR,
    fill_color: ColorRGBA | None | dai.Color | None = TRANSPARENT_PRIMARY_COLOR,
    thickness: float = 1.0,
    closed: bool = False,
) -> AnnotationHelper
```

Draws a polyline.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `points` | `list[Point] | list[dai.Point2f]` | List of points of the polyline | required |
| `outline_color` | `ColorRGBA | dai.Color` | Outline color | `PRIMARY_COLOR` |
| `fill_color` | `ColorRGBA | None | dai.Color | None` | Fill color (None for no fill) | `TRANSPARENT_PRIMARY_COLOR` |
| `thickness` | `float` | Line thickness | `1.0` |
| `closed` | `bool` | Creates polygon, instead of polyline if True | `False` |

Returns

| Type | Description |
| --- | --- |
| `AnnotationHelper` | self |

#### method `draw_rectangle`

```python
def draw_rectangle(
    top_left: Point | dai.Point2f,
    bottom_right: Point | dai.Point2f,
    outline_color: ColorRGBA | dai.Color = PRIMARY_COLOR,
    fill_color: ColorRGBA | None | dai.Color | None = TRANSPARENT_PRIMARY_COLOR,
    thickness: float = 1.0,
    clip_to_viewport: bool = False,
) -> AnnotationHelper
```

Draws a rectangle.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `top_left` | `Point | dai.Point2f` | Top left corner of the rectangle | required |
| `bottom_right` | `Point | dai.Point2f` | Bottom right corner of the rectangle | required |
| `outline_color` | `ColorRGBA | dai.Color` | Outline color | `PRIMARY_COLOR` |
| `fill_color` | `ColorRGBA | None | dai.Color | None` | Fill color (None for no fill) | `TRANSPARENT_PRIMARY_COLOR` |
| `thickness` | `float` | Outline thickness | `1.0` |
| `clip_to_viewport` | `bool` | Indication whether to clip the line to the viewport | `False` |

Returns

| Type | Description |
| --- | --- |
| `AnnotationHelper` | self |

#### method `draw_rotated_rect`

```python
def draw_rotated_rect(
    center: Point | dai.Point2f,
    size: tuple[float, float] | dai.Size2f,
    angle: float,
    outline_color: ColorRGBA | dai.Color = PRIMARY_COLOR,
    fill_color: ColorRGBA | None | dai.Color | None = TRANSPARENT_PRIMARY_COLOR,
    thickness: float = 1.0,
    clip_to_viewport: bool = False,
) -> AnnotationHelper
```

Draws a rotated rectangle.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `center` | `Point | dai.Point2f` | Center of the rectangle | required |
| `size` | `tuple[float, float] | dai.Size2f` | Size of the rectangle (width, height) | required |
| `angle` | `float` | Angle of rotation in degrees | required |
| `outline_color` | `ColorRGBA | dai.Color` | Outline color | `PRIMARY_COLOR` |
| `fill_color` | `ColorRGBA | None | dai.Color | None` | Fill color (None for no fill) | `TRANSPARENT_PRIMARY_COLOR` |
| `thickness` | `float` | Outline thickness | `1.0` |
| `clip_to_viewport` | `bool` | Indication whether to clip the line to the viewport | `False` |

Returns

| Type | Description |
| --- | --- |
| `AnnotationHelper` | self |

#### method `draw_text`

```python
def draw_text(
    text: str,
    position: Point | dai.Point2f,
    color: ColorRGBA | dai.Color = PRIMARY_COLOR,
    background_color: ColorRGBA | None | dai.Color | None = None,
    size: float = 32,
) -> AnnotationHelper
```

Draws text.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `text` | `str` | Text string | required |
| `position` | `Point | dai.Point2f` | Text position | required |
| `color` | `ColorRGBA | dai.Color` | Text color | `PRIMARY_COLOR` |
| `background_color` | `ColorRGBA | None | dai.Color | None` | Background color (None for no background) | `None` |
| `size` | `float` | Text size | `32` |

Returns

| Type | Description |
| --- | --- |
| `AnnotationHelper` | self |

## Module Attributes

| Name | Description |
| --- | --- |
| [`ColorRGBA`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Module-Attributes-ColorRGBA) |  |
| [`Point`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/annotation_helper.md#annotation_helper-Module-Attributes-Point) |  |

### type alias `ColorRGBA`

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

### type alias `Point`

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