Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,7 @@ def getAnnotator(
color: str,
opacity: float,
) -> sv.annotators.base.BaseAnnotator:
key = "_".join(
map(
str,
[
color,
opacity,
],
)
)
key = (color, opacity)

if key not in self.annotatorCache:
background_color = str_to_color(color)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import supervision as sv

_COLOR_NAMES = {name for name in dir(sv.Color) if not name.startswith("_")}


def str_to_color(color: str) -> sv.Color:
if color.startswith("#"):
Expand All @@ -10,7 +12,7 @@ def str_to_color(color: str) -> sv.Color:
elif color.startswith("bgr"):
b, g, r = map(int, color[4:-1].split(","))
return sv.Color.from_bgr_tuple((b, g, r))
elif hasattr(sv.Color, color.upper()):
elif color.upper() in _COLOR_NAMES:
return getattr(sv.Color, color.upper())
else:
raise ValueError(
Expand Down