Skip to content

Annotators

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> bounding_box_annotator = sv.BoundingBoxAnnotator()
>>> annotated_frame = bounding_box_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

bounding-box-annotator-example

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> mask_annotator = sv.MaskAnnotator()
>>> annotated_frame = mask_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

mask-annotator-example

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> ellipse_annotator = sv.EllipseAnnotator()
>>> annotated_frame = ellipse_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

ellipse-annotator-example

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> corner_annotator = sv.BoxCornerAnnotator()
>>> annotated_frame = corner_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

box-corner-annotator-example

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> circle_annotator = sv.CircleAnnotator()
>>> annotated_frame = circle_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

circle-annotator-example

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER)
>>> annotated_frame = label_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

label-annotator-example

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> blur_annotator = sv.BlurAnnotator()
>>> annotated_frame = blur_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

blur-annotator-example

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> trace_annotator = sv.TraceAnnotator()
>>> annotated_frame = trace_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

trace-annotator-example

BoundingBoxAnnotator

Bases: BaseAnnotator

A class for drawing bounding boxes on an image using provided detections.

Source code in supervision/annotators/core.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class BoundingBoxAnnotator(BaseAnnotator):
    """
    A class for drawing bounding boxes on an image using provided detections.
    """

    def __init__(
        self,
        color: Union[Color, ColorPalette] = ColorPalette.default(),
        thickness: int = 2,
        color_map: str = "class",
    ):
        """
        Args:
            color (Union[Color, ColorPalette]): The color or color palette to use for
                annotating detections.
            thickness (int): Thickness of the bounding box lines.
            color_map (str): Strategy for mapping colors to annotations.
                Options are `index`, `class`, or `track`.
        """
        self.color: Union[Color, ColorPalette] = color
        self.thickness: int = thickness
        self.color_map: ColorMap = ColorMap(color_map)

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        """
        Annotates the given scene with bounding boxes based on the provided detections.

        Args:
            scene (np.ndarray): The image where bounding boxes will be drawn.
            detections (Detections): Object detections to annotate.

        Returns:
            np.ndarray: The annotated image.

        Example:
            ```python
            >>> import supervision as sv

            >>> image = ...
            >>> detections = sv.Detections(...)

            >>> bounding_box_annotator = sv.BoundingBoxAnnotator()
            >>> annotated_frame = bounding_box_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )
            ```

        ![bounding-box-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/bounding-box-annotator-example.png)
        """
        for detection_idx in range(len(detections)):
            x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
            idx = resolve_color_idx(
                detections=detections,
                detection_idx=detection_idx,
                color_map=self.color_map,
            )
            color = resolve_color(color=self.color, idx=idx)
            cv2.rectangle(
                img=scene,
                pt1=(x1, y1),
                pt2=(x2, y2),
                color=color.as_bgr(),
                thickness=self.thickness,
            )
        return scene

__init__(color=ColorPalette.default(), thickness=2, color_map='class')

Parameters:

Name Type Description Default
color Union[Color, ColorPalette]

The color or color palette to use for annotating detections.

default()
thickness int

Thickness of the bounding box lines.

2
color_map str

Strategy for mapping colors to annotations. Options are index, class, or track.

'class'
Source code in supervision/annotators/core.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def __init__(
    self,
    color: Union[Color, ColorPalette] = ColorPalette.default(),
    thickness: int = 2,
    color_map: str = "class",
):
    """
    Args:
        color (Union[Color, ColorPalette]): The color or color palette to use for
            annotating detections.
        thickness (int): Thickness of the bounding box lines.
        color_map (str): Strategy for mapping colors to annotations.
            Options are `index`, `class`, or `track`.
    """
    self.color: Union[Color, ColorPalette] = color
    self.thickness: int = thickness
    self.color_map: ColorMap = ColorMap(color_map)

annotate(scene, detections)

Annotates the given scene with bounding boxes based on the provided detections.

Parameters:

Name Type Description Default
scene ndarray

The image where bounding boxes will be drawn.

required
detections Detections

Object detections to annotate.

required

Returns:

Type Description
ndarray

np.ndarray: The annotated image.

Example
>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> bounding_box_annotator = sv.BoundingBoxAnnotator()
>>> annotated_frame = bounding_box_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

bounding-box-annotator-example

Source code in supervision/annotators/core.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
    """
    Annotates the given scene with bounding boxes based on the provided detections.

    Args:
        scene (np.ndarray): The image where bounding boxes will be drawn.
        detections (Detections): Object detections to annotate.

    Returns:
        np.ndarray: The annotated image.

    Example:
        ```python
        >>> import supervision as sv

        >>> image = ...
        >>> detections = sv.Detections(...)

        >>> bounding_box_annotator = sv.BoundingBoxAnnotator()
        >>> annotated_frame = bounding_box_annotator.annotate(
        ...     scene=image.copy(),
        ...     detections=detections
        ... )
        ```

    ![bounding-box-annotator-example](https://media.roboflow.com/
    supervision-annotator-examples/bounding-box-annotator-example.png)
    """
    for detection_idx in range(len(detections)):
        x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
        idx = resolve_color_idx(
            detections=detections,
            detection_idx=detection_idx,
            color_map=self.color_map,
        )
        color = resolve_color(color=self.color, idx=idx)
        cv2.rectangle(
            img=scene,
            pt1=(x1, y1),
            pt2=(x2, y2),
            color=color.as_bgr(),
            thickness=self.thickness,
        )
    return scene

MaskAnnotator

Bases: BaseAnnotator

A class for drawing masks on an image using provided detections.

Source code in supervision/annotators/core.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
class MaskAnnotator(BaseAnnotator):
    """
    A class for drawing masks on an image using provided detections.
    """

    def __init__(
        self,
        color: Union[Color, ColorPalette] = ColorPalette.default(),
        opacity: float = 0.5,
        color_map: str = "class",
    ):
        """
        Args:
            color (Union[Color, ColorPalette]): The color or color palette to use for
                annotating detections.
            opacity (float): Opacity of the overlay mask. Must be between `0` and `1`.
            color_map (str): Strategy for mapping colors to annotations.
                Options are `index`, `class`, or `track`.
        """
        self.color: Union[Color, ColorPalette] = color
        self.opacity = opacity
        self.color_map: ColorMap = ColorMap(color_map)

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        """
        Annotates the given scene with masks based on the provided detections.

        Args:
            scene (np.ndarray): The image where masks will be drawn.
            detections (Detections): Object detections to annotate.

        Returns:
            np.ndarray: The annotated image.

        Example:
            ```python
            >>> import supervision as sv

            >>> image = ...
            >>> detections = sv.Detections(...)

            >>> mask_annotator = sv.MaskAnnotator()
            >>> annotated_frame = mask_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )
            ```

        ![mask-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/mask-annotator-example.png)
        """
        if detections.mask is None:
            return scene

        for detection_idx in np.flip(np.argsort(detections.area)):
            idx = resolve_color_idx(
                detections=detections,
                detection_idx=detection_idx,
                color_map=self.color_map,
            )
            color = resolve_color(color=self.color, idx=idx)
            mask = detections.mask[detection_idx]
            colored_mask = np.zeros_like(scene, dtype=np.uint8)
            colored_mask[:] = color.as_bgr()

            scene = np.where(
                np.expand_dims(mask, axis=-1),
                np.uint8(self.opacity * colored_mask + (1 - self.opacity) * scene),
                scene,
            )
        return scene

__init__(color=ColorPalette.default(), opacity=0.5, color_map='class')

Parameters:

Name Type Description Default
color Union[Color, ColorPalette]

The color or color palette to use for annotating detections.

default()
opacity float

Opacity of the overlay mask. Must be between 0 and 1.

0.5
color_map str

Strategy for mapping colors to annotations. Options are index, class, or track.

'class'
Source code in supervision/annotators/core.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def __init__(
    self,
    color: Union[Color, ColorPalette] = ColorPalette.default(),
    opacity: float = 0.5,
    color_map: str = "class",
):
    """
    Args:
        color (Union[Color, ColorPalette]): The color or color palette to use for
            annotating detections.
        opacity (float): Opacity of the overlay mask. Must be between `0` and `1`.
        color_map (str): Strategy for mapping colors to annotations.
            Options are `index`, `class`, or `track`.
    """
    self.color: Union[Color, ColorPalette] = color
    self.opacity = opacity
    self.color_map: ColorMap = ColorMap(color_map)

annotate(scene, detections)

Annotates the given scene with masks based on the provided detections.

Parameters:

Name Type Description Default
scene ndarray

The image where masks will be drawn.

required
detections Detections

Object detections to annotate.

required

Returns:

Type Description
ndarray

np.ndarray: The annotated image.

Example
>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> mask_annotator = sv.MaskAnnotator()
>>> annotated_frame = mask_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

mask-annotator-example

Source code in supervision/annotators/core.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
    """
    Annotates the given scene with masks based on the provided detections.

    Args:
        scene (np.ndarray): The image where masks will be drawn.
        detections (Detections): Object detections to annotate.

    Returns:
        np.ndarray: The annotated image.

    Example:
        ```python
        >>> import supervision as sv

        >>> image = ...
        >>> detections = sv.Detections(...)

        >>> mask_annotator = sv.MaskAnnotator()
        >>> annotated_frame = mask_annotator.annotate(
        ...     scene=image.copy(),
        ...     detections=detections
        ... )
        ```

    ![mask-annotator-example](https://media.roboflow.com/
    supervision-annotator-examples/mask-annotator-example.png)
    """
    if detections.mask is None:
        return scene

    for detection_idx in np.flip(np.argsort(detections.area)):
        idx = resolve_color_idx(
            detections=detections,
            detection_idx=detection_idx,
            color_map=self.color_map,
        )
        color = resolve_color(color=self.color, idx=idx)
        mask = detections.mask[detection_idx]
        colored_mask = np.zeros_like(scene, dtype=np.uint8)
        colored_mask[:] = color.as_bgr()

        scene = np.where(
            np.expand_dims(mask, axis=-1),
            np.uint8(self.opacity * colored_mask + (1 - self.opacity) * scene),
            scene,
        )
    return scene

EllipseAnnotator

Bases: BaseAnnotator

A class for drawing ellipses on an image using provided detections.

Source code in supervision/annotators/core.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
class EllipseAnnotator(BaseAnnotator):
    """
    A class for drawing ellipses on an image using provided detections.
    """

    def __init__(
        self,
        color: Union[Color, ColorPalette] = ColorPalette.default(),
        thickness: int = 2,
        start_angle: int = -45,
        end_angle: int = 235,
        color_map: str = "class",
    ):
        """
        Args:
            color (Union[Color, ColorPalette]): The color or color palette to use for
                annotating detections.
            thickness (int): Thickness of the ellipse lines.
            start_angle (int): Starting angle of the ellipse.
            end_angle (int): Ending angle of the ellipse.
            color_map (str): Strategy for mapping colors to annotations.
                Options are `index`, `class`, or `track`.
        """
        self.color: Union[Color, ColorPalette] = color
        self.thickness: int = thickness
        self.start_angle: int = start_angle
        self.end_angle: int = end_angle
        self.color_map: ColorMap = ColorMap(color_map)

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        """
        Annotates the given scene with ellipses based on the provided detections.

        Args:
            scene (np.ndarray): The image where ellipses will be drawn.
            detections (Detections): Object detections to annotate.

        Returns:
            np.ndarray: The annotated image.

        Example:
            ```python
            >>> import supervision as sv

            >>> image = ...
            >>> detections = sv.Detections(...)

            >>> ellipse_annotator = sv.EllipseAnnotator()
            >>> annotated_frame = ellipse_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )
            ```

        ![ellipse-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/ellipse-annotator-example.png)
        """
        for detection_idx in range(len(detections)):
            x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
            idx = resolve_color_idx(
                detections=detections,
                detection_idx=detection_idx,
                color_map=self.color_map,
            )
            color = resolve_color(color=self.color, idx=idx)

            center = (int((x1 + x2) / 2), y2)
            width = x2 - x1
            cv2.ellipse(
                scene,
                center=center,
                axes=(int(width), int(0.35 * width)),
                angle=0.0,
                startAngle=self.start_angle,
                endAngle=self.end_angle,
                color=color.as_bgr(),
                thickness=self.thickness,
                lineType=cv2.LINE_4,
            )
        return scene

__init__(color=ColorPalette.default(), thickness=2, start_angle=-45, end_angle=235, color_map='class')

Parameters:

Name Type Description Default
color Union[Color, ColorPalette]

The color or color palette to use for annotating detections.

default()
thickness int

Thickness of the ellipse lines.

2
start_angle int

Starting angle of the ellipse.

-45
end_angle int

Ending angle of the ellipse.

235
color_map str

Strategy for mapping colors to annotations. Options are index, class, or track.

'class'
Source code in supervision/annotators/core.py
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
def __init__(
    self,
    color: Union[Color, ColorPalette] = ColorPalette.default(),
    thickness: int = 2,
    start_angle: int = -45,
    end_angle: int = 235,
    color_map: str = "class",
):
    """
    Args:
        color (Union[Color, ColorPalette]): The color or color palette to use for
            annotating detections.
        thickness (int): Thickness of the ellipse lines.
        start_angle (int): Starting angle of the ellipse.
        end_angle (int): Ending angle of the ellipse.
        color_map (str): Strategy for mapping colors to annotations.
            Options are `index`, `class`, or `track`.
    """
    self.color: Union[Color, ColorPalette] = color
    self.thickness: int = thickness
    self.start_angle: int = start_angle
    self.end_angle: int = end_angle
    self.color_map: ColorMap = ColorMap(color_map)

annotate(scene, detections)

Annotates the given scene with ellipses based on the provided detections.

Parameters:

Name Type Description Default
scene ndarray

The image where ellipses will be drawn.

required
detections Detections

Object detections to annotate.

required

Returns:

Type Description
ndarray

np.ndarray: The annotated image.

Example
>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> ellipse_annotator = sv.EllipseAnnotator()
>>> annotated_frame = ellipse_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

ellipse-annotator-example

Source code in supervision/annotators/core.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
    """
    Annotates the given scene with ellipses based on the provided detections.

    Args:
        scene (np.ndarray): The image where ellipses will be drawn.
        detections (Detections): Object detections to annotate.

    Returns:
        np.ndarray: The annotated image.

    Example:
        ```python
        >>> import supervision as sv

        >>> image = ...
        >>> detections = sv.Detections(...)

        >>> ellipse_annotator = sv.EllipseAnnotator()
        >>> annotated_frame = ellipse_annotator.annotate(
        ...     scene=image.copy(),
        ...     detections=detections
        ... )
        ```

    ![ellipse-annotator-example](https://media.roboflow.com/
    supervision-annotator-examples/ellipse-annotator-example.png)
    """
    for detection_idx in range(len(detections)):
        x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
        idx = resolve_color_idx(
            detections=detections,
            detection_idx=detection_idx,
            color_map=self.color_map,
        )
        color = resolve_color(color=self.color, idx=idx)

        center = (int((x1 + x2) / 2), y2)
        width = x2 - x1
        cv2.ellipse(
            scene,
            center=center,
            axes=(int(width), int(0.35 * width)),
            angle=0.0,
            startAngle=self.start_angle,
            endAngle=self.end_angle,
            color=color.as_bgr(),
            thickness=self.thickness,
            lineType=cv2.LINE_4,
        )
    return scene

BoxCornerAnnotator

Bases: BaseAnnotator

A class for drawing box corners on an image using provided detections.

Source code in supervision/annotators/core.py
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
class BoxCornerAnnotator(BaseAnnotator):
    """
    A class for drawing box corners on an image using provided detections.
    """

    def __init__(
        self,
        color: Union[Color, ColorPalette] = ColorPalette.default(),
        thickness: int = 4,
        corner_length: int = 25,
        color_map: str = "class",
    ):
        """
        Args:
            color (Union[Color, ColorPalette]): The color or color palette to use for
                annotating detections.
            thickness (int): Thickness of the corner lines.
            corner_length (int): Length of each corner line.
            color_map (str): Strategy for mapping colors to annotations.
                Options are `index`, `class`, or `track`.
        """
        self.color: Union[Color, ColorPalette] = color
        self.thickness: int = thickness
        self.corner_length: int = corner_length
        self.color_map: ColorMap = ColorMap(color_map)

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        """
        Annotates the given scene with box corners based on the provided detections.

        Args:
            scene (np.ndarray): The image where box corners will be drawn.
            detections (Detections): Object detections to annotate.

        Returns:
            np.ndarray: The annotated image.

        Example:
            ```python
            >>> import supervision as sv

            >>> image = ...
            >>> detections = sv.Detections(...)

            >>> corner_annotator = sv.BoxCornerAnnotator()
            >>> annotated_frame = corner_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )
            ```

        ![box-corner-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/box-corner-annotator-example.png)
        """
        for detection_idx in range(len(detections)):
            x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
            idx = resolve_color_idx(
                detections=detections,
                detection_idx=detection_idx,
                color_map=self.color_map,
            )
            color = resolve_color(color=self.color, idx=idx)
            corners = [(x1, y1), (x2, y1), (x1, y2), (x2, y2)]

            for x, y in corners:
                x_end = x + self.corner_length if x == x1 else x - self.corner_length
                cv2.line(
                    scene, (x, y), (x_end, y), color.as_bgr(), thickness=self.thickness
                )

                y_end = y + self.corner_length if y == y1 else y - self.corner_length
                cv2.line(
                    scene, (x, y), (x, y_end), color.as_bgr(), thickness=self.thickness
                )
        return scene

__init__(color=ColorPalette.default(), thickness=4, corner_length=25, color_map='class')

Parameters:

Name Type Description Default
color Union[Color, ColorPalette]

The color or color palette to use for annotating detections.

default()
thickness int

Thickness of the corner lines.

4
corner_length int

Length of each corner line.

25
color_map str

Strategy for mapping colors to annotations. Options are index, class, or track.

'class'
Source code in supervision/annotators/core.py
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
def __init__(
    self,
    color: Union[Color, ColorPalette] = ColorPalette.default(),
    thickness: int = 4,
    corner_length: int = 25,
    color_map: str = "class",
):
    """
    Args:
        color (Union[Color, ColorPalette]): The color or color palette to use for
            annotating detections.
        thickness (int): Thickness of the corner lines.
        corner_length (int): Length of each corner line.
        color_map (str): Strategy for mapping colors to annotations.
            Options are `index`, `class`, or `track`.
    """
    self.color: Union[Color, ColorPalette] = color
    self.thickness: int = thickness
    self.corner_length: int = corner_length
    self.color_map: ColorMap = ColorMap(color_map)

annotate(scene, detections)

Annotates the given scene with box corners based on the provided detections.

Parameters:

Name Type Description Default
scene ndarray

The image where box corners will be drawn.

required
detections Detections

Object detections to annotate.

required

Returns:

Type Description
ndarray

np.ndarray: The annotated image.

Example
>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> corner_annotator = sv.BoxCornerAnnotator()
>>> annotated_frame = corner_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

box-corner-annotator-example

Source code in supervision/annotators/core.py
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
    """
    Annotates the given scene with box corners based on the provided detections.

    Args:
        scene (np.ndarray): The image where box corners will be drawn.
        detections (Detections): Object detections to annotate.

    Returns:
        np.ndarray: The annotated image.

    Example:
        ```python
        >>> import supervision as sv

        >>> image = ...
        >>> detections = sv.Detections(...)

        >>> corner_annotator = sv.BoxCornerAnnotator()
        >>> annotated_frame = corner_annotator.annotate(
        ...     scene=image.copy(),
        ...     detections=detections
        ... )
        ```

    ![box-corner-annotator-example](https://media.roboflow.com/
    supervision-annotator-examples/box-corner-annotator-example.png)
    """
    for detection_idx in range(len(detections)):
        x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
        idx = resolve_color_idx(
            detections=detections,
            detection_idx=detection_idx,
            color_map=self.color_map,
        )
        color = resolve_color(color=self.color, idx=idx)
        corners = [(x1, y1), (x2, y1), (x1, y2), (x2, y2)]

        for x, y in corners:
            x_end = x + self.corner_length if x == x1 else x - self.corner_length
            cv2.line(
                scene, (x, y), (x_end, y), color.as_bgr(), thickness=self.thickness
            )

            y_end = y + self.corner_length if y == y1 else y - self.corner_length
            cv2.line(
                scene, (x, y), (x, y_end), color.as_bgr(), thickness=self.thickness
            )
    return scene

CircleAnnotator

Bases: BaseAnnotator

A class for drawing circle on an image using provided detections.

Source code in supervision/annotators/core.py
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
class CircleAnnotator(BaseAnnotator):
    """
    A class for drawing circle on an image using provided detections.
    """

    def __init__(
        self,
        color: Union[Color, ColorPalette] = ColorPalette.default(),
        thickness: int = 4,
        color_map: str = "class",
    ):
        """
        Args:
            color (Union[Color, ColorPalette]): The color or color palette to use for
                annotating detections.
            thickness (int): Thickness of the circle line.
            color_map (str): Strategy for mapping colors to annotations.
                Options are `index`, `class`, or `track`.
        """

        self.color: Union[Color, ColorPalette] = color
        self.thickness: int = thickness
        self.color_map: ColorMap = ColorMap(color_map)

    def annotate(
        self,
        scene: np.ndarray,
        detections: Detections,
    ) -> np.ndarray:
        """
        Annotates the given scene with circles based on the provided detections.

        Args:
            scene (np.ndarray): The image where box corners will be drawn.
            detections (Detections): Object detections to annotate.

        Returns:
            np.ndarray: The annotated image.

        Example:
            ```python
            >>> import supervision as sv

            >>> image = ...
            >>> detections = sv.Detections(...)

            >>> circle_annotator = sv.CircleAnnotator()
            >>> annotated_frame = circle_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )
            ```


        ![circle-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/circle-annotator-example.png)
        """
        for detection_idx in range(len(detections)):
            x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
            center = ((x1 + x2) // 2, (y1 + y2) // 2)
            distance = sqrt((x1 - center[0]) ** 2 + (y1 - center[1]) ** 2)

            idx = resolve_color_idx(
                detections=detections,
                detection_idx=detection_idx,
                color_map=self.color_map,
            )

            color = (
                self.color.by_idx(idx)
                if isinstance(self.color, ColorPalette)
                else self.color
            )

            cv2.circle(
                img=scene,
                center=center,
                radius=int(distance),
                color=color.as_bgr(),
                thickness=self.thickness,
            )

        return scene

__init__(color=ColorPalette.default(), thickness=4, color_map='class')

Parameters:

Name Type Description Default
color Union[Color, ColorPalette]

The color or color palette to use for annotating detections.

default()
thickness int

Thickness of the circle line.

4
color_map str

Strategy for mapping colors to annotations. Options are index, class, or track.

'class'
Source code in supervision/annotators/core.py
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
def __init__(
    self,
    color: Union[Color, ColorPalette] = ColorPalette.default(),
    thickness: int = 4,
    color_map: str = "class",
):
    """
    Args:
        color (Union[Color, ColorPalette]): The color or color palette to use for
            annotating detections.
        thickness (int): Thickness of the circle line.
        color_map (str): Strategy for mapping colors to annotations.
            Options are `index`, `class`, or `track`.
    """

    self.color: Union[Color, ColorPalette] = color
    self.thickness: int = thickness
    self.color_map: ColorMap = ColorMap(color_map)

annotate(scene, detections)

Annotates the given scene with circles based on the provided detections.

Parameters:

Name Type Description Default
scene ndarray

The image where box corners will be drawn.

required
detections Detections

Object detections to annotate.

required

Returns:

Type Description
ndarray

np.ndarray: The annotated image.

Example
>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> circle_annotator = sv.CircleAnnotator()
>>> annotated_frame = circle_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

circle-annotator-example

Source code in supervision/annotators/core.py
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
def annotate(
    self,
    scene: np.ndarray,
    detections: Detections,
) -> np.ndarray:
    """
    Annotates the given scene with circles based on the provided detections.

    Args:
        scene (np.ndarray): The image where box corners will be drawn.
        detections (Detections): Object detections to annotate.

    Returns:
        np.ndarray: The annotated image.

    Example:
        ```python
        >>> import supervision as sv

        >>> image = ...
        >>> detections = sv.Detections(...)

        >>> circle_annotator = sv.CircleAnnotator()
        >>> annotated_frame = circle_annotator.annotate(
        ...     scene=image.copy(),
        ...     detections=detections
        ... )
        ```


    ![circle-annotator-example](https://media.roboflow.com/
    supervision-annotator-examples/circle-annotator-example.png)
    """
    for detection_idx in range(len(detections)):
        x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
        center = ((x1 + x2) // 2, (y1 + y2) // 2)
        distance = sqrt((x1 - center[0]) ** 2 + (y1 - center[1]) ** 2)

        idx = resolve_color_idx(
            detections=detections,
            detection_idx=detection_idx,
            color_map=self.color_map,
        )

        color = (
            self.color.by_idx(idx)
            if isinstance(self.color, ColorPalette)
            else self.color
        )

        cv2.circle(
            img=scene,
            center=center,
            radius=int(distance),
            color=color.as_bgr(),
            thickness=self.thickness,
        )

    return scene

LabelAnnotator

A class for annotating labels on an image using provided detections.

Source code in supervision/annotators/core.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
class LabelAnnotator:
    """
    A class for annotating labels on an image using provided detections.
    """

    def __init__(
        self,
        color: Union[Color, ColorPalette] = ColorPalette.default(),
        text_color: Color = Color.black(),
        text_scale: float = 0.5,
        text_thickness: int = 1,
        text_padding: int = 10,
        text_position: Position = Position.TOP_LEFT,
        color_map: str = "class",
    ):
        """
        Args:
            color (Union[Color, ColorPalette]): The color or color palette to use for
                annotating the text background.
            text_color (Color): The color to use for the text.
            text_scale (float): Font scale for the text.
            text_thickness (int): Thickness of the text characters.
            text_padding (int): Padding around the text within its background box.
            text_position (Position): Position of the text relative to the detection.
                Possible values are defined in the `Position` enum.
            color_map (str): Strategy for mapping colors to annotations.
                Options are `index`, `class`, or `track`.
        """
        self.color: Union[Color, ColorPalette] = color
        self.text_color: Color = text_color
        self.text_scale: float = text_scale
        self.text_thickness: int = text_thickness
        self.text_padding: int = text_padding
        self.text_position: Position = text_position
        self.color_map: ColorMap = ColorMap(color_map)

    @staticmethod
    def resolve_text_background_xyxy(
        detection_xyxy: Tuple[int, int, int, int],
        text_wh: Tuple[int, int],
        text_padding: int,
        position: Position,
    ) -> Tuple[int, int, int, int]:
        padded_text_wh = (text_wh[0] + 2 * text_padding, text_wh[1] + 2 * text_padding)
        x1, y1, x2, y2 = detection_xyxy
        center_x = (x1 + x2) // 2
        center_y = (y1 + y2) // 2

        if position == Position.TOP_LEFT:
            return x1, y1 - padded_text_wh[1], x1 + padded_text_wh[0], y1
        elif position == Position.TOP_RIGHT:
            return x2 - padded_text_wh[0], y1 - padded_text_wh[1], x2, y1
        elif position == Position.TOP_CENTER:
            return (
                center_x - padded_text_wh[0] // 2,
                y1 - padded_text_wh[1],
                center_x + padded_text_wh[0] // 2,
                y1,
            )
        elif position == Position.CENTER:
            return (
                center_x - padded_text_wh[0] // 2,
                center_y - padded_text_wh[1] // 2,
                center_x + padded_text_wh[0] // 2,
                center_y + padded_text_wh[1] // 2,
            )
        elif position == Position.BOTTOM_LEFT:
            return x1, y2, x1 + padded_text_wh[0], y2 + padded_text_wh[1]
        elif position == Position.BOTTOM_RIGHT:
            return x2 - padded_text_wh[0], y2, x2, y2 + padded_text_wh[1]
        elif position == Position.BOTTOM_CENTER:
            return (
                center_x - padded_text_wh[0] // 2,
                y2,
                center_x + padded_text_wh[0] // 2,
                y2 + padded_text_wh[1],
            )

    def annotate(
        self,
        scene: np.ndarray,
        detections: Detections,
        labels: List[str] = None,
    ) -> np.ndarray:
        """
        Annotates the given scene with labels based on the provided detections.

        Args:
            scene (np.ndarray): The image where labels will be drawn.
            detections (Detections): Object detections to annotate.
            labels (List[str]): Optional. Custom labels for each detection.

        Returns:
            np.ndarray: The annotated image.

        Example:
            ```python
            >>> import supervision as sv

            >>> image = ...
            >>> detections = sv.Detections(...)

            >>> label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER)
            >>> annotated_frame = label_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )
            ```

        ![label-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/label-annotator-example-2.png)
        """
        font = cv2.FONT_HERSHEY_SIMPLEX
        for detection_idx in range(len(detections)):
            detection_xyxy = detections.xyxy[detection_idx].astype(int)
            idx = resolve_color_idx(
                detections=detections,
                detection_idx=detection_idx,
                color_map=self.color_map,
            )
            color = resolve_color(color=self.color, idx=idx)
            text = (
                f"{detections.class_id[detection_idx]}"
                if (labels is None or len(detections) != len(labels))
                else labels[detection_idx]
            )
            text_wh = cv2.getTextSize(
                text=text,
                fontFace=font,
                fontScale=self.text_scale,
                thickness=self.text_thickness,
            )[0]

            text_background_xyxy = self.resolve_text_background_xyxy(
                detection_xyxy=detection_xyxy,
                text_wh=text_wh,
                text_padding=self.text_padding,
                position=self.text_position,
            )

            text_x = text_background_xyxy[0] + self.text_padding
            text_y = text_background_xyxy[1] + self.text_padding + text_wh[1]

            cv2.rectangle(
                img=scene,
                pt1=(text_background_xyxy[0], text_background_xyxy[1]),
                pt2=(text_background_xyxy[2], text_background_xyxy[3]),
                color=color.as_bgr(),
                thickness=cv2.FILLED,
            )
            cv2.putText(
                img=scene,
                text=text,
                org=(text_x, text_y),
                fontFace=font,
                fontScale=self.text_scale,
                color=self.text_color.as_rgb(),
                thickness=self.text_thickness,
                lineType=cv2.LINE_AA,
            )
        return scene

__init__(color=ColorPalette.default(), text_color=Color.black(), text_scale=0.5, text_thickness=1, text_padding=10, text_position=Position.TOP_LEFT, color_map='class')

Parameters:

Name Type Description Default
color Union[Color, ColorPalette]

The color or color palette to use for annotating the text background.

default()
text_color Color

The color to use for the text.

black()
text_scale float

Font scale for the text.

0.5
text_thickness int

Thickness of the text characters.

1
text_padding int

Padding around the text within its background box.

10
text_position Position

Position of the text relative to the detection. Possible values are defined in the Position enum.

TOP_LEFT
color_map str

Strategy for mapping colors to annotations. Options are index, class, or track.

'class'
Source code in supervision/annotators/core.py
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
def __init__(
    self,
    color: Union[Color, ColorPalette] = ColorPalette.default(),
    text_color: Color = Color.black(),
    text_scale: float = 0.5,
    text_thickness: int = 1,
    text_padding: int = 10,
    text_position: Position = Position.TOP_LEFT,
    color_map: str = "class",
):
    """
    Args:
        color (Union[Color, ColorPalette]): The color or color palette to use for
            annotating the text background.
        text_color (Color): The color to use for the text.
        text_scale (float): Font scale for the text.
        text_thickness (int): Thickness of the text characters.
        text_padding (int): Padding around the text within its background box.
        text_position (Position): Position of the text relative to the detection.
            Possible values are defined in the `Position` enum.
        color_map (str): Strategy for mapping colors to annotations.
            Options are `index`, `class`, or `track`.
    """
    self.color: Union[Color, ColorPalette] = color
    self.text_color: Color = text_color
    self.text_scale: float = text_scale
    self.text_thickness: int = text_thickness
    self.text_padding: int = text_padding
    self.text_position: Position = text_position
    self.color_map: ColorMap = ColorMap(color_map)

annotate(scene, detections, labels=None)

Annotates the given scene with labels based on the provided detections.

Parameters:

Name Type Description Default
scene ndarray

The image where labels will be drawn.

required
detections Detections

Object detections to annotate.

required
labels List[str]

Optional. Custom labels for each detection.

None

Returns:

Type Description
ndarray

np.ndarray: The annotated image.

Example
>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER)
>>> annotated_frame = label_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

label-annotator-example

Source code in supervision/annotators/core.py
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
def annotate(
    self,
    scene: np.ndarray,
    detections: Detections,
    labels: List[str] = None,
) -> np.ndarray:
    """
    Annotates the given scene with labels based on the provided detections.

    Args:
        scene (np.ndarray): The image where labels will be drawn.
        detections (Detections): Object detections to annotate.
        labels (List[str]): Optional. Custom labels for each detection.

    Returns:
        np.ndarray: The annotated image.

    Example:
        ```python
        >>> import supervision as sv

        >>> image = ...
        >>> detections = sv.Detections(...)

        >>> label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER)
        >>> annotated_frame = label_annotator.annotate(
        ...     scene=image.copy(),
        ...     detections=detections
        ... )
        ```

    ![label-annotator-example](https://media.roboflow.com/
    supervision-annotator-examples/label-annotator-example-2.png)
    """
    font = cv2.FONT_HERSHEY_SIMPLEX
    for detection_idx in range(len(detections)):
        detection_xyxy = detections.xyxy[detection_idx].astype(int)
        idx = resolve_color_idx(
            detections=detections,
            detection_idx=detection_idx,
            color_map=self.color_map,
        )
        color = resolve_color(color=self.color, idx=idx)
        text = (
            f"{detections.class_id[detection_idx]}"
            if (labels is None or len(detections) != len(labels))
            else labels[detection_idx]
        )
        text_wh = cv2.getTextSize(
            text=text,
            fontFace=font,
            fontScale=self.text_scale,
            thickness=self.text_thickness,
        )[0]

        text_background_xyxy = self.resolve_text_background_xyxy(
            detection_xyxy=detection_xyxy,
            text_wh=text_wh,
            text_padding=self.text_padding,
            position=self.text_position,
        )

        text_x = text_background_xyxy[0] + self.text_padding
        text_y = text_background_xyxy[1] + self.text_padding + text_wh[1]

        cv2.rectangle(
            img=scene,
            pt1=(text_background_xyxy[0], text_background_xyxy[1]),
            pt2=(text_background_xyxy[2], text_background_xyxy[3]),
            color=color.as_bgr(),
            thickness=cv2.FILLED,
        )
        cv2.putText(
            img=scene,
            text=text,
            org=(text_x, text_y),
            fontFace=font,
            fontScale=self.text_scale,
            color=self.text_color.as_rgb(),
            thickness=self.text_thickness,
            lineType=cv2.LINE_AA,
        )
    return scene

TraceAnnotator

A class for drawing trace paths on an image based on detection coordinates.

Warning

This annotator utilizes the tracker_id. Read here to learn how to plug tracking into your inference pipeline.

Source code in supervision/annotators/core.py
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
class TraceAnnotator:
    """
    A class for drawing trace paths on an image based on detection coordinates.

    !!! warning

        This annotator utilizes the `tracker_id`. Read
        [here](https://supervision.roboflow.com/trackers/) to learn how to plug
        tracking into your inference pipeline.
    """

    def __init__(
        self,
        color: Union[Color, ColorPalette] = ColorPalette.default(),
        position: Optional[Position] = Position.CENTER,
        trace_length: int = 30,
        thickness: int = 2,
        color_map: str = "class",
    ):
        """
        Args:
            color (Union[Color, ColorPalette]): The color to draw the trace, can be
                a single color or a color palette.
            position (Optional[Position]): The position of the trace.
                Defaults to `CENTER`.
            trace_length (int): The maximum length of the trace in terms of historical
                points. Defaults to `30`.
            thickness (int): The thickness of the trace lines. Defaults to `2`.
            color_map (str): Strategy for mapping colors to annotations.
                Options are `index`, `class`, or `track`.
        """
        self.color: Union[Color, ColorPalette] = color
        self.position = position
        self.trace = Trace(max_size=trace_length)
        self.thickness = thickness
        self.color_map: ColorMap = ColorMap(color_map)

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        """
        Draws trace paths on the frame based on the detection coordinates provided.

        Args:
            scene (np.ndarray): The image on which the traces will be drawn.
            detections (Detections): The detections which include coordinates for
                which the traces will be drawn.

        Returns:
            np.ndarray: The image with the trace paths drawn on it.

        Example:
            ```python
            >>> import supervision as sv

            >>> image = ...
            >>> detections = sv.Detections(...)

            >>> trace_annotator = sv.TraceAnnotator()
            >>> annotated_frame = trace_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )
            ```

        ![trace-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/trace-annotator-example.png)
        """
        self.trace.put(detections)

        for detection_idx in range(len(detections)):
            tracker_id = int(detections.tracker_id[detection_idx])
            idx = resolve_color_idx(
                detections=detections,
                detection_idx=detection_idx,
                color_map=self.color_map,
            )
            color = resolve_color(color=self.color, idx=idx)
            xy = self.trace.get(tracker_id=tracker_id)
            if len(xy) > 1:
                scene = cv2.polylines(
                    scene,
                    [xy.astype(np.int32)],
                    False,
                    color=color.as_bgr(),
                    thickness=self.thickness,
                )
        return scene

__init__(color=ColorPalette.default(), position=Position.CENTER, trace_length=30, thickness=2, color_map='class')

Parameters:

Name Type Description Default
color Union[Color, ColorPalette]

The color to draw the trace, can be a single color or a color palette.

default()
position Optional[Position]

The position of the trace. Defaults to CENTER.

CENTER
trace_length int

The maximum length of the trace in terms of historical points. Defaults to 30.

30
thickness int

The thickness of the trace lines. Defaults to 2.

2
color_map str

Strategy for mapping colors to annotations. Options are index, class, or track.

'class'
Source code in supervision/annotators/core.py
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
def __init__(
    self,
    color: Union[Color, ColorPalette] = ColorPalette.default(),
    position: Optional[Position] = Position.CENTER,
    trace_length: int = 30,
    thickness: int = 2,
    color_map: str = "class",
):
    """
    Args:
        color (Union[Color, ColorPalette]): The color to draw the trace, can be
            a single color or a color palette.
        position (Optional[Position]): The position of the trace.
            Defaults to `CENTER`.
        trace_length (int): The maximum length of the trace in terms of historical
            points. Defaults to `30`.
        thickness (int): The thickness of the trace lines. Defaults to `2`.
        color_map (str): Strategy for mapping colors to annotations.
            Options are `index`, `class`, or `track`.
    """
    self.color: Union[Color, ColorPalette] = color
    self.position = position
    self.trace = Trace(max_size=trace_length)
    self.thickness = thickness
    self.color_map: ColorMap = ColorMap(color_map)

annotate(scene, detections)

Draws trace paths on the frame based on the detection coordinates provided.

Parameters:

Name Type Description Default
scene ndarray

The image on which the traces will be drawn.

required
detections Detections

The detections which include coordinates for which the traces will be drawn.

required

Returns:

Type Description
ndarray

np.ndarray: The image with the trace paths drawn on it.

Example
>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> trace_annotator = sv.TraceAnnotator()
>>> annotated_frame = trace_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

trace-annotator-example

Source code in supervision/annotators/core.py
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
    """
    Draws trace paths on the frame based on the detection coordinates provided.

    Args:
        scene (np.ndarray): The image on which the traces will be drawn.
        detections (Detections): The detections which include coordinates for
            which the traces will be drawn.

    Returns:
        np.ndarray: The image with the trace paths drawn on it.

    Example:
        ```python
        >>> import supervision as sv

        >>> image = ...
        >>> detections = sv.Detections(...)

        >>> trace_annotator = sv.TraceAnnotator()
        >>> annotated_frame = trace_annotator.annotate(
        ...     scene=image.copy(),
        ...     detections=detections
        ... )
        ```

    ![trace-annotator-example](https://media.roboflow.com/
    supervision-annotator-examples/trace-annotator-example.png)
    """
    self.trace.put(detections)

    for detection_idx in range(len(detections)):
        tracker_id = int(detections.tracker_id[detection_idx])
        idx = resolve_color_idx(
            detections=detections,
            detection_idx=detection_idx,
            color_map=self.color_map,
        )
        color = resolve_color(color=self.color, idx=idx)
        xy = self.trace.get(tracker_id=tracker_id)
        if len(xy) > 1:
            scene = cv2.polylines(
                scene,
                [xy.astype(np.int32)],
                False,
                color=color.as_bgr(),
                thickness=self.thickness,
            )
    return scene

BlurAnnotator

Bases: BaseAnnotator

A class for blurring regions in an image using provided detections.

Source code in supervision/annotators/core.py
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
class BlurAnnotator(BaseAnnotator):
    """
    A class for blurring regions in an image using provided detections.
    """

    def __init__(self, kernel_size: int = 15):
        """
        Args:
            kernel_size (int): The size of the average pooling kernel used for blurring.
        """
        self.kernel_size: int = kernel_size

    def annotate(
        self,
        scene: np.ndarray,
        detections: Detections,
    ) -> np.ndarray:
        """
        Annotates the given scene by blurring regions based on the provided detections.

        Args:
            scene (np.ndarray): The image where blurring will be applied.
            detections (Detections): Object detections to annotate.

        Returns:
            np.ndarray: The annotated image.

        Example:
            ```python
            >>> import supervision as sv

            >>> image = ...
            >>> detections = sv.Detections(...)

            >>> blur_annotator = sv.BlurAnnotator()
            >>> annotated_frame = blur_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )
            ```

        ![blur-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/blur-annotator-example-2.png)
        """
        for detection_idx in range(len(detections)):
            x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
            roi = scene[y1:y2, x1:x2]

            roi = cv2.blur(roi, (self.kernel_size, self.kernel_size))
            scene[y1:y2, x1:x2] = roi

        return scene

__init__(kernel_size=15)

Parameters:

Name Type Description Default
kernel_size int

The size of the average pooling kernel used for blurring.

15
Source code in supervision/annotators/core.py
573
574
575
576
577
578
def __init__(self, kernel_size: int = 15):
    """
    Args:
        kernel_size (int): The size of the average pooling kernel used for blurring.
    """
    self.kernel_size: int = kernel_size

annotate(scene, detections)

Annotates the given scene by blurring regions based on the provided detections.

Parameters:

Name Type Description Default
scene ndarray

The image where blurring will be applied.

required
detections Detections

Object detections to annotate.

required

Returns:

Type Description
ndarray

np.ndarray: The annotated image.

Example
>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> blur_annotator = sv.BlurAnnotator()
>>> annotated_frame = blur_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

blur-annotator-example

Source code in supervision/annotators/core.py
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
def annotate(
    self,
    scene: np.ndarray,
    detections: Detections,
) -> np.ndarray:
    """
    Annotates the given scene by blurring regions based on the provided detections.

    Args:
        scene (np.ndarray): The image where blurring will be applied.
        detections (Detections): Object detections to annotate.

    Returns:
        np.ndarray: The annotated image.

    Example:
        ```python
        >>> import supervision as sv

        >>> image = ...
        >>> detections = sv.Detections(...)

        >>> blur_annotator = sv.BlurAnnotator()
        >>> annotated_frame = blur_annotator.annotate(
        ...     scene=image.copy(),
        ...     detections=detections
        ... )
        ```

    ![blur-annotator-example](https://media.roboflow.com/
    supervision-annotator-examples/blur-annotator-example-2.png)
    """
    for detection_idx in range(len(detections)):
        x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
        roi = scene[y1:y2, x1:x2]

        roi = cv2.blur(roi, (self.kernel_size, self.kernel_size))
        scene[y1:y2, x1:x2] = roi

    return scene