|
5 | 5 | import numpy as np |
6 | 6 |
|
7 | 7 | from supervision.annotators.base import BaseAnnotator |
8 | | -from supervision.annotators.utils import ( |
9 | | - ColorLookup, |
10 | | - Trace, |
11 | | - resolve_color, |
12 | | -) |
| 8 | +from supervision.annotators.utils import ColorLookup, Trace, resolve_color |
13 | 9 | from supervision.detection.core import Detections |
14 | 10 | from supervision.draw.color import Color, ColorPalette |
15 | 11 | from supervision.geometry.core import Position |
@@ -42,7 +38,7 @@ def annotate( |
42 | 38 | self, |
43 | 39 | scene: np.ndarray, |
44 | 40 | detections: Detections, |
45 | | - custom_color_lookup: Optional[np.ndarray] = None |
| 41 | + custom_color_lookup: Optional[np.ndarray] = None, |
46 | 42 | ) -> np.ndarray: |
47 | 43 | """ |
48 | 44 | Annotates the given scene with bounding boxes based on the provided detections. |
@@ -79,8 +75,9 @@ def annotate( |
79 | 75 | color=self.color, |
80 | 76 | detections=detections, |
81 | 77 | detection_idx=detection_idx, |
82 | | - color_lookup=self.color_lookup if |
83 | | - custom_color_lookup is None else custom_color_lookup |
| 78 | + color_lookup=self.color_lookup |
| 79 | + if custom_color_lookup is None |
| 80 | + else custom_color_lookup, |
84 | 81 | ) |
85 | 82 | cv2.rectangle( |
86 | 83 | img=scene, |
@@ -119,7 +116,7 @@ def annotate( |
119 | 116 | self, |
120 | 117 | scene: np.ndarray, |
121 | 118 | detections: Detections, |
122 | | - custom_color_lookup: Optional[np.ndarray] = None |
| 119 | + custom_color_lookup: Optional[np.ndarray] = None, |
123 | 120 | ) -> np.ndarray: |
124 | 121 | """ |
125 | 122 | Annotates the given scene with masks based on the provided detections. |
@@ -158,8 +155,9 @@ def annotate( |
158 | 155 | color=self.color, |
159 | 156 | detections=detections, |
160 | 157 | detection_idx=detection_idx, |
161 | | - color_lookup=self.color_lookup if |
162 | | - custom_color_lookup is None else custom_color_lookup |
| 158 | + color_lookup=self.color_lookup |
| 159 | + if custom_color_lookup is None |
| 160 | + else custom_color_lookup, |
163 | 161 | ) |
164 | 162 | mask = detections.mask[detection_idx] |
165 | 163 | colored_mask = np.zeros_like(scene, dtype=np.uint8) |
@@ -198,7 +196,7 @@ def annotate( |
198 | 196 | self, |
199 | 197 | scene: np.ndarray, |
200 | 198 | detections: Detections, |
201 | | - custom_color_lookup: Optional[np.ndarray] = None |
| 199 | + custom_color_lookup: Optional[np.ndarray] = None, |
202 | 200 | ) -> np.ndarray: |
203 | 201 | """ |
204 | 202 | Annotates the given scene with box masks based on the provided detections. |
@@ -236,8 +234,9 @@ def annotate( |
236 | 234 | color=self.color, |
237 | 235 | detections=detections, |
238 | 236 | detection_idx=detection_idx, |
239 | | - color_lookup=self.color_lookup if |
240 | | - custom_color_lookup is None else custom_color_lookup |
| 237 | + color_lookup=self.color_lookup |
| 238 | + if custom_color_lookup is None |
| 239 | + else custom_color_lookup, |
241 | 240 | ) |
242 | 241 | cv2.rectangle( |
243 | 242 | img=scene, |
@@ -283,7 +282,7 @@ def annotate( |
283 | 282 | self, |
284 | 283 | scene: np.ndarray, |
285 | 284 | detections: Detections, |
286 | | - custom_color_lookup: Optional[np.ndarray] = None |
| 285 | + custom_color_lookup: Optional[np.ndarray] = None, |
287 | 286 | ) -> np.ndarray: |
288 | 287 | """ |
289 | 288 | Annotates the given scene with halos based on the provided detections. |
@@ -326,8 +325,9 @@ def annotate( |
326 | 325 | color=self.color, |
327 | 326 | detections=detections, |
328 | 327 | detection_idx=detection_idx, |
329 | | - color_lookup=self.color_lookup if |
330 | | - custom_color_lookup is None else custom_color_lookup |
| 328 | + color_lookup=self.color_lookup |
| 329 | + if custom_color_lookup is None |
| 330 | + else custom_color_lookup, |
331 | 331 | ) |
332 | 332 | mask = detections.mask[detection_idx] |
333 | 333 | fmask = np.logical_or(fmask, mask) |
@@ -376,7 +376,7 @@ def annotate( |
376 | 376 | self, |
377 | 377 | scene: np.ndarray, |
378 | 378 | detections: Detections, |
379 | | - custom_color_lookup: Optional[np.ndarray] = None |
| 379 | + custom_color_lookup: Optional[np.ndarray] = None, |
380 | 380 | ) -> np.ndarray: |
381 | 381 | """ |
382 | 382 | Annotates the given scene with ellipses based on the provided detections. |
@@ -413,8 +413,9 @@ def annotate( |
413 | 413 | color=self.color, |
414 | 414 | detections=detections, |
415 | 415 | detection_idx=detection_idx, |
416 | | - color_lookup=self.color_lookup if |
417 | | - custom_color_lookup is None else custom_color_lookup |
| 416 | + color_lookup=self.color_lookup |
| 417 | + if custom_color_lookup is None |
| 418 | + else custom_color_lookup, |
418 | 419 | ) |
419 | 420 | center = (int((x1 + x2) / 2), y2) |
420 | 421 | width = x2 - x1 |
@@ -462,7 +463,7 @@ def annotate( |
462 | 463 | self, |
463 | 464 | scene: np.ndarray, |
464 | 465 | detections: Detections, |
465 | | - custom_color_lookup: Optional[np.ndarray] = None |
| 466 | + custom_color_lookup: Optional[np.ndarray] = None, |
466 | 467 | ) -> np.ndarray: |
467 | 468 | """ |
468 | 469 | Annotates the given scene with box corners based on the provided detections. |
@@ -499,8 +500,9 @@ def annotate( |
499 | 500 | color=self.color, |
500 | 501 | detections=detections, |
501 | 502 | detection_idx=detection_idx, |
502 | | - color_lookup=self.color_lookup if |
503 | | - custom_color_lookup is None else custom_color_lookup |
| 503 | + color_lookup=self.color_lookup |
| 504 | + if custom_color_lookup is None |
| 505 | + else custom_color_lookup, |
504 | 506 | ) |
505 | 507 | corners = [(x1, y1), (x2, y1), (x1, y2), (x2, y2)] |
506 | 508 |
|
@@ -545,7 +547,7 @@ def annotate( |
545 | 547 | self, |
546 | 548 | scene: np.ndarray, |
547 | 549 | detections: Detections, |
548 | | - custom_color_lookup: Optional[np.ndarray] = None |
| 550 | + custom_color_lookup: Optional[np.ndarray] = None, |
549 | 551 | ) -> np.ndarray: |
550 | 552 | """ |
551 | 553 | Annotates the given scene with circles based on the provided detections. |
@@ -585,8 +587,9 @@ def annotate( |
585 | 587 | color=self.color, |
586 | 588 | detections=detections, |
587 | 589 | detection_idx=detection_idx, |
588 | | - color_lookup=self.color_lookup if |
589 | | - custom_color_lookup is None else custom_color_lookup |
| 590 | + color_lookup=self.color_lookup |
| 591 | + if custom_color_lookup is None |
| 592 | + else custom_color_lookup, |
590 | 593 | ) |
591 | 594 | cv2.circle( |
592 | 595 | img=scene, |
@@ -682,7 +685,7 @@ def annotate( |
682 | 685 | scene: np.ndarray, |
683 | 686 | detections: Detections, |
684 | 687 | labels: List[str] = None, |
685 | | - custom_color_lookup: Optional[np.ndarray] = None |
| 688 | + custom_color_lookup: Optional[np.ndarray] = None, |
686 | 689 | ) -> np.ndarray: |
687 | 690 | """ |
688 | 691 | Annotates the given scene with labels based on the provided detections. |
@@ -721,8 +724,9 @@ def annotate( |
721 | 724 | color=self.color, |
722 | 725 | detections=detections, |
723 | 726 | detection_idx=detection_idx, |
724 | | - color_lookup=self.color_lookup if |
725 | | - custom_color_lookup is None else custom_color_lookup |
| 727 | + color_lookup=self.color_lookup |
| 728 | + if custom_color_lookup is None |
| 729 | + else custom_color_lookup, |
726 | 730 | ) |
727 | 731 | text = ( |
728 | 732 | f"{detections.class_id[detection_idx]}" |
@@ -861,7 +865,7 @@ def annotate( |
861 | 865 | self, |
862 | 866 | scene: np.ndarray, |
863 | 867 | detections: Detections, |
864 | | - custom_color_lookup: Optional[np.ndarray] = None |
| 868 | + custom_color_lookup: Optional[np.ndarray] = None, |
865 | 869 | ) -> np.ndarray: |
866 | 870 | """ |
867 | 871 | Draws trace paths on the frame based on the detection coordinates provided. |
@@ -901,8 +905,9 @@ def annotate( |
901 | 905 | color=self.color, |
902 | 906 | detections=detections, |
903 | 907 | detection_idx=detection_idx, |
904 | | - color_lookup=self.color_lookup if |
905 | | - custom_color_lookup is None else custom_color_lookup |
| 908 | + color_lookup=self.color_lookup |
| 909 | + if custom_color_lookup is None |
| 910 | + else custom_color_lookup, |
906 | 911 | ) |
907 | 912 | xy = self.trace.get(tracker_id=tracker_id) |
908 | 913 | if len(xy) > 1: |
|
0 commit comments