Skip to content

Added the flag draw_scores to the function draw_boxes. #219

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

Merged
merged 2 commits into from
Dec 1, 2022
Merged
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
2 changes: 1 addition & 1 deletion demos/motmetrics4norfair/src/motmetrics4norfair.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np

from norfair import drawing, metrics, Tracker, video
from norfair import Tracker, drawing, metrics, video
from norfair.camera_motion import MotionEstimator
from norfair.filter import FilterPyKalmanFilterFactory

Expand Down
10 changes: 8 additions & 2 deletions norfair/drawing/draw_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def draw_boxes(
detections: Sequence["Detection"] = None, # Deprecated
line_color: Optional[ColorLike] = None, # Deprecated
line_width: Optional[int] = None, # Deprecated
label_size: Optional[int] = None, # Deprecated
label_size: Optional[int] = None, # Deprecated´
draw_scores: bool = False,
) -> np.ndarray:
"""
Draw bounding boxes corresponding to Detections or TrackedObjects.
Expand Down Expand Up @@ -63,6 +64,9 @@ def draw_boxes(
draw_labels : bool, optional
If set to True, the label is added to a title that is drawn on top of the box.
If an object doesn't have a label this parameter is ignored.
draw_scores : bool, optional
If set to True, the score is added to a title that is drawn on top of the box.
If an object doesn't have a label this parameter is ignored.
text_size : Optional[float], optional
Size of the title, the value is used as a multiplier of the base size of the font.
By default the size is scaled automatically based on the frame size.
Expand Down Expand Up @@ -148,7 +152,9 @@ def draw_boxes(
thickness=thickness,
)

text = _build_text(d, draw_labels=draw_labels, draw_ids=draw_ids)
text = _build_text(
d, draw_labels=draw_labels, draw_ids=draw_ids, draw_scores=draw_scores
)
if text:
if text_color is None:
obj_text_color = obj_color
Expand Down
11 changes: 9 additions & 2 deletions norfair/drawing/draw_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def draw_points(
hide_dead_points: bool = True,
detections: Sequence["Detection"] = None, # deprecated
label_size: Optional[int] = None, # deprecated
draw_scores: bool = False,
) -> np.ndarray:
"""
Draw the points included in a list of Detections or TrackedObjects.
Expand Down Expand Up @@ -61,6 +62,9 @@ def draw_points(
draw_labels : bool, optional
If set to True, the label is added to a title that is drawn on top of the box.
If an object doesn't have a label this parameter is ignored.
draw_scores : bool, optional
If set to True, the score is added to a title that is drawn on top of the box.
If an object doesn't have a label this parameter is ignored.
text_size : Optional[int], optional
Size of the title, the value is used as a multiplier of the base size of the font.
By default the size is scaled automatically based on the frame size.
Expand Down Expand Up @@ -152,10 +156,12 @@ def draw_points(
thickness=thickness,
)

if draw_labels or draw_ids:
if draw_labels or draw_ids or draw_scores:
position = d.points[d.live_points].mean(axis=0)
position -= radius
text = _build_text(d, draw_labels=draw_labels, draw_ids=draw_ids)
text = _build_text(
d, draw_labels=draw_labels, draw_ids=draw_ids, draw_scores=draw_scores
)

Drawer.text(
frame,
Expand All @@ -165,6 +171,7 @@ def draw_points(
color=obj_text_color,
thickness=text_thickness,
)

return frame


Expand Down
6 changes: 5 additions & 1 deletion norfair/drawing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ def _centroid(tracked_points: np.ndarray) -> Tuple[int, int]:
return int(sum_x / num_points), int(sum_y / num_points)


def _build_text(drawable: "Drawable", draw_labels, draw_ids):
def _build_text(drawable: "Drawable", draw_labels, draw_ids, draw_scores):
text = ""
if draw_labels and drawable.label is not None:
text = str(drawable.label)
if draw_ids and drawable.id is not None:
if len(text) > 0:
text += "-"
text += str(drawable.id)
if draw_scores and drawable.scores is not None:
if len(text) > 0:
text += "-"
text += str(np.round(np.mean(drawable.scores), 4))
return text