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

Support custom list of colors in draw_tracked_boxes (renames line_color to border_colors and line_width to border_width). #54

Merged
merged 1 commit into from
May 27, 2021
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
26 changes: 15 additions & 11 deletions norfair/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,29 @@ def draw_boxes(frame, detections, line_color=None, line_width=None, random_color
def draw_tracked_boxes(
dekked marked this conversation as resolved.
Show resolved Hide resolved
frame,
objects,
line_color=None,
line_width=None,
border_colors=None,
border_width=None,
id_size=None,
id_thickness=None,
draw_box=True,
):
frame_scale = frame.shape[0] / 100
if line_width is None:
line_width = int(frame_scale * 0.5)
if border_width is None:
border_width = int(frame_scale * 0.5)
if id_size is None:
id_size = frame_scale / 10
if id_thickness is None:
id_thickness = int(frame_scale / 5)
color_is_None = line_color == None
for obj in objects:
if isinstance(border_colors, tuple):
border_colors = [border_colors]

for n, obj in enumerate(objects):
if not obj.live_points.any():
continue
if color_is_None:
line_color = Color.random(obj.id)
if border_colors is None:
color = Color.random(obj.id)
else:
color = border_colors[n % len(border_colors)]

if draw_box:
points = obj.estimate
Expand All @@ -250,8 +254,8 @@ def draw_tracked_boxes(
frame,
tuple(points[0, :]),
tuple(points[1, :]),
color=line_color,
thickness=line_width,
color=color,
thickness=border_width,
)

if id_size > 0:
Expand All @@ -263,7 +267,7 @@ def draw_tracked_boxes(
tuple(id_draw_position),
cv2.FONT_HERSHEY_SIMPLEX,
id_size,
line_color,
color,
id_thickness,
cv2.LINE_AA,
)
Expand Down