Skip to content
Open
42 changes: 21 additions & 21 deletions src/supervision/annotators/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
PENDING_TRACK_ID,
ColorLookup,
Trace,
_resolve_detection_color,
_validate_labels,
calculate_dynamic_kernel_size,
calculate_dynamic_pixel_size,
get_labels_text,
hex_to_rgba,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hex_to_rgba,
hex_to_rgba,
resolve_color,

resolve_color,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check this issue and consider also deprecating it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding back in sugegstion #2343 (comment)

resolve_text_background_xyxy,
snap_boxes,
wrap_text,
Expand Down Expand Up @@ -256,7 +256,7 @@ def annotate(
return scene
for detection_idx in range(len(detections)):
x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -347,7 +347,7 @@ def annotate(

for detection_idx in range(len(detections)):
obb = obb_boxes[detection_idx]
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -398,7 +398,7 @@ def _paint_masks_by_area(
)
compact_mask = masks if isinstance(masks, CompactMask) else None
for detection_idx in np.flip(np.argsort(detections.area)):
color_bgr = resolve_color(
color_bgr = _resolve_detection_color(
color=color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -584,7 +584,7 @@ def annotate(

for detection_idx in range(len(detections)):
mask = detections.mask[detection_idx]
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -673,7 +673,7 @@ def annotate(
scene_with_boxes = scene.copy()
for detection_idx in range(len(detections)):
x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -872,7 +872,7 @@ def annotate(
return scene
for detection_idx in range(len(detections)):
x1, _y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -968,7 +968,7 @@ def annotate(
return scene
for detection_idx in range(len(detections)):
x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -1064,7 +1064,7 @@ def annotate(
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)
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -1164,7 +1164,7 @@ def annotate(
return scene
xy = detections.get_anchors_coordinates(anchor=self.position)
for detection_idx in range(len(detections)):
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand All @@ -1176,7 +1176,7 @@ def annotate(

cv2.circle(scene, center, self.radius, color.as_bgr(), -1)
if self.outline_thickness:
outline_color = resolve_color(
outline_color = _resolve_detection_color(
color=self.outline_color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -1405,13 +1405,13 @@ def _draw_labels(
)

for idx, label_property in enumerate(label_properties):
background_color = resolve_color(
background_color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=idx,
color_lookup=color_lookup,
)
text_color = resolve_color(
text_color = _resolve_detection_color(
color=self.text_color,
detections=detections,
detection_idx=idx,
Expand Down Expand Up @@ -1718,13 +1718,13 @@ def _draw_labels(
)

for idx, label_property in enumerate(label_properties):
background_color = resolve_color(
background_color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=idx,
color_lookup=color_lookup,
)
text_color = resolve_color(
text_color = _resolve_detection_color(
color=self.text_color,
detections=detections,
detection_idx=idx,
Expand Down Expand Up @@ -2079,7 +2079,7 @@ def annotate(
if tracker_id_val is None:
continue
tracker_id = int(tracker_id_val)
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=filtered_detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -2406,7 +2406,7 @@ def annotate(
return scene
xy = detections.get_anchors_coordinates(anchor=self.position)
for detection_idx in range(len(detections)):
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand All @@ -2426,7 +2426,7 @@ def annotate(

cv2.fillPoly(scene, [vertices], color.as_bgr())
if self.outline_thickness:
outline_color = resolve_color(
outline_color = _resolve_detection_color(
color=self.outline_color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -2523,7 +2523,7 @@ def annotate(
return scene
for detection_idx in range(len(detections)):
x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -2691,7 +2691,7 @@ def annotate(
assert detections.confidence is not None # MyPy type hint
value = detections.confidence[detection_idx]

color = resolve_color(
color = _resolve_detection_color(
color=self.color,
detections=detections,
detection_idx=detection_idx,
Expand Down Expand Up @@ -2882,7 +2882,7 @@ def annotate(
anchor=anchor, crop_wh=crop_wh, position=self.position
)
scene = overlay_image(image=scene, overlay=resized_crop, anchor=(x1, y1))
color = resolve_color(
color = _resolve_detection_color(
color=self.border_color,
detections=detections,
detection_idx=idx,
Expand Down
Loading
Loading