From 60d33ca140c31f19dfa92120d5b52b9e337a3a5e Mon Sep 17 00:00:00 2001 From: Bhavay Malhotra Date: Sat, 20 Jul 2024 17:30:18 +0530 Subject: [PATCH] Updated the text_color parameter --- supervision/annotators/core.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index 6d34ae5c..7102d186 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -1011,7 +1011,7 @@ class LabelAnnotator(BaseAnnotator): def __init__( self, color: Union[Color, ColorPalette] = ColorPalette.DEFAULT, - text_color: Color = Color.WHITE, + text_color: Union[Color, ColorPalette] = ColorPalette.DEFAULT, text_scale: float = 0.5, text_thickness: int = 1, text_padding: int = 10, @@ -1023,7 +1023,7 @@ class LabelAnnotator(BaseAnnotator): 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_color (Union[Color, ColorPalette]): The color or color palette 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. @@ -1036,7 +1036,7 @@ class LabelAnnotator(BaseAnnotator): """ self.border_radius: int = border_radius self.color: Union[Color, ColorPalette] = color - self.text_color: Color = text_color + self.text_color: Union[Color, ColorPalette] = text_color self.text_scale: float = text_scale self.text_thickness: int = text_thickness self.text_padding: int = text_padding @@ -1114,6 +1114,17 @@ class LabelAnnotator(BaseAnnotator): ), ) + text_color = resolve_color( + color=self.text_color, + detections=detections, + detection_idx=detection_idx, + color_lookup=( + self.color_lookup + if custom_color_lookup is None + else custom_color_lookup + ), + ) + if labels is not None: text = labels[detection_idx] elif detections[CLASS_NAME_DATA_FIELD] is not None: @@ -1152,7 +1163,7 @@ class LabelAnnotator(BaseAnnotator): org=(text_x, text_y), fontFace=font, fontScale=self.text_scale, - color=self.text_color.as_bgr(), + color=text_color.as_bgr(), thickness=self.text_thickness, lineType=cv2.LINE_AA, )