Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TriangleAnnotator, DotAnnotator] - allow customization of the contour color #1403 #1458

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions supervision/annotators/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ def __init__(
position: Position = Position.CENTER,
color_lookup: ColorLookup = ColorLookup.CLASS,
outline_thickness: int = 0,
outline_color: Union[Color, ColorPalette] = Color.BLACK,
):
"""
Args:
Expand All @@ -937,12 +938,16 @@ def __init__(
color_lookup (ColorLookup): Strategy for mapping colors to annotations.
Options are `INDEX`, `CLASS`, `TRACK`.
outline_thickness (int): Thickness of the outline of the dot.
outline_color (Union[Color, ColorPalette]): The color or color palette to
use for outline. It is activated by setting outline_thickness to a value
greater than 0.
"""
self.color: Union[Color, ColorPalette] = color
self.radius: int = radius
self.position: Position = position
self.color_lookup: ColorLookup = color_lookup
self.outline_thickness = outline_thickness
self.outline_color: Union[Color, ColorPalette] = outline_color

@ensure_cv2_image_for_annotation
def annotate(
Expand Down Expand Up @@ -997,8 +1002,20 @@ def annotate(

cv2.circle(scene, center, self.radius, color.as_bgr(), -1)
if self.outline_thickness:
outline_color = resolve_color(
color=self.outline_color,
detections=detections,
detection_idx=detection_idx,
color_lookup=self.color_lookup
if custom_color_lookup is None
else custom_color_lookup,
)
cv2.circle(
scene, center, self.radius, (0, 0, 0), self.outline_thickness
scene,
center,
self.radius,
outline_color.as_bgr(),
self.outline_thickness,
)
return scene

Expand Down Expand Up @@ -1744,6 +1761,7 @@ def __init__(
position: Position = Position.TOP_CENTER,
color_lookup: ColorLookup = ColorLookup.CLASS,
outline_thickness: int = 0,
outline_color: Union[Color, ColorPalette] = Color.BLACK,
):
"""
Args:
Expand All @@ -1755,13 +1773,17 @@ def __init__(
color_lookup (ColorLookup): Strategy for mapping colors to annotations.
Options are `INDEX`, `CLASS`, `TRACK`.
outline_thickness (int): Thickness of the outline of the triangle.
outline_color (Union[Color, ColorPalette]): The color or color palette to
use for outline. It is activated by setting outline_thickness to a value
greater than 0.
"""
self.color: Union[Color, ColorPalette] = color
self.base: int = base
self.height: int = height
self.position: Position = position
self.color_lookup: ColorLookup = color_lookup
self.outline_thickness: int = outline_thickness
self.outline_color: Union[Color, ColorPalette] = outline_color

@ensure_cv2_image_for_annotation
def annotate(
Expand Down Expand Up @@ -1824,8 +1846,20 @@ def annotate(

cv2.fillPoly(scene, [vertices], color.as_bgr())
if self.outline_thickness:
outline_color = resolve_color(
color=self.outline_color,
detections=detections,
detection_idx=detection_idx,
color_lookup=self.color_lookup
if custom_color_lookup is None
else custom_color_lookup,
)
cv2.polylines(
scene, [vertices], True, (0, 0, 0), thickness=self.outline_thickness
scene,
[vertices],
True,
outline_color.as_bgr(),
thickness=self.outline_thickness,
)
return scene

Expand Down