-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Added Union[Color, ColorPalette] to text_color parameter #1387
Changes from 1 commit
60d33ca
073500b
0210f51
16b8102
3fb6a7b
01922f8
1f6694b
e2f33fa
c5d052e
a0abf2d
b8e1612
b103ce4
9956d5d
37a988f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1055,7 +1055,6 @@ def annotate( | |
detections: Detections, | ||
labels: Optional[List[str]] = None, | ||
custom_color_lookup: Optional[np.ndarray] = None, | ||
custom_text_color_lookup: Optional[np.ndarray] = None, | ||
) -> ImageType: | ||
""" | ||
Annotates the given scene with labels based on the provided detections. | ||
|
@@ -1068,9 +1067,7 @@ def annotate( | |
labels (Optional[List[str]]): Custom labels for each detection. | ||
custom_color_lookup (Optional[np.ndarray]): Custom color lookup array. | ||
Allows to override the default color mapping strategy. | ||
custom_text_color_lookup (Optional[np.ndarray]): Custom text color lookup | ||
array. Allows to override the default text color mapping strategy. | ||
|
||
|
||
Returns: | ||
The annotated image, matching the type of `scene` (`numpy.ndarray` | ||
or `PIL.Image.Image`) | ||
|
@@ -1128,8 +1125,8 @@ def annotate( | |
detection_idx=detection_idx, | ||
color_lookup=( | ||
self.text_color_lookup | ||
if custom_text_color_lookup is None | ||
else custom_text_color_lookup | ||
if custom_color_lookup is None | ||
else custom_color_lookup | ||
), | ||
) | ||
|
||
|
@@ -1235,6 +1232,7 @@ def __init__( | |
text_padding: int = 10, | ||
text_position: Position = Position.TOP_LEFT, | ||
color_lookup: ColorLookup = ColorLookup.CLASS, | ||
text_color_lookup: ColorLookup = ColorLookup.CLASS, | ||
border_radius: int = 0, | ||
): | ||
""" | ||
|
@@ -1250,6 +1248,8 @@ def __init__( | |
Possible values are defined in the `Position` enum. | ||
color_lookup (ColorLookup): Strategy for mapping colors to annotations. | ||
Options are `INDEX`, `CLASS`, `TRACK`. | ||
text_color_lookup (ColorLookup): Strategy for mapping text colors to | ||
annotations. Options are `INDEX`, `CLASS`, `TRACK`. | ||
border_radius (int): The radius to apply round edges. If the selected | ||
value is higher than the lower dimension, width or height, is clipped. | ||
""" | ||
|
@@ -1258,6 +1258,7 @@ def __init__( | |
self.text_padding = text_padding | ||
self.text_anchor = text_position | ||
self.color_lookup = color_lookup | ||
self.text_color_lookup: ColorLookup = text_color_lookup | ||
self.border_radius = border_radius | ||
if font_path is not None: | ||
try: | ||
|
@@ -1336,6 +1337,18 @@ def annotate( | |
else custom_color_lookup | ||
), | ||
) | ||
|
||
text_color = resolve_color( | ||
color=self.text_color, | ||
detections=detections, | ||
detection_idx=detection_idx, | ||
color_lookup=( | ||
self.text_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: | ||
|
@@ -1369,7 +1382,7 @@ def annotate( | |
xy=(text_x, text_y), | ||
text=text, | ||
font=self.font, | ||
fill=self.text_color.as_rgb(), | ||
fill=text_color.as_rgb(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this, do we need to change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
return scene | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this parameter and use only
color_lookup
.