diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index ca2a71f86..e0002e864 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -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: @@ -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( @@ -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 @@ -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: @@ -1755,6 +1773,9 @@ 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 @@ -1762,6 +1783,7 @@ def __init__( 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( @@ -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