Skip to content

Commit a4891a0

Browse files
authored
Merge pull request #219 from moooises/draw_score
Added the flag draw_scores to the function draw_boxes.
2 parents 40dc70a + 263d599 commit a4891a0

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

demos/motmetrics4norfair/src/motmetrics4norfair.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import numpy as np
55

6-
from norfair import drawing, metrics, Tracker, video
6+
from norfair import Tracker, drawing, metrics, video
77
from norfair.camera_motion import MotionEstimator
88
from norfair.filter import FilterPyKalmanFilterFactory
99

norfair/drawing/draw_boxes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def draw_boxes(
2626
detections: Sequence["Detection"] = None, # Deprecated
2727
line_color: Optional[ColorLike] = None, # Deprecated
2828
line_width: Optional[int] = None, # Deprecated
29-
label_size: Optional[int] = None, # Deprecated
29+
label_size: Optional[int] = None, # Deprecated´
30+
draw_scores: bool = False,
3031
) -> np.ndarray:
3132
"""
3233
Draw bounding boxes corresponding to Detections or TrackedObjects.
@@ -63,6 +64,9 @@ def draw_boxes(
6364
draw_labels : bool, optional
6465
If set to True, the label is added to a title that is drawn on top of the box.
6566
If an object doesn't have a label this parameter is ignored.
67+
draw_scores : bool, optional
68+
If set to True, the score is added to a title that is drawn on top of the box.
69+
If an object doesn't have a label this parameter is ignored.
6670
text_size : Optional[float], optional
6771
Size of the title, the value is used as a multiplier of the base size of the font.
6872
By default the size is scaled automatically based on the frame size.
@@ -148,7 +152,9 @@ def draw_boxes(
148152
thickness=thickness,
149153
)
150154

151-
text = _build_text(d, draw_labels=draw_labels, draw_ids=draw_ids)
155+
text = _build_text(
156+
d, draw_labels=draw_labels, draw_ids=draw_ids, draw_scores=draw_scores
157+
)
152158
if text:
153159
if text_color is None:
154160
obj_text_color = obj_color

norfair/drawing/draw_points.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def draw_points(
2626
hide_dead_points: bool = True,
2727
detections: Sequence["Detection"] = None, # deprecated
2828
label_size: Optional[int] = None, # deprecated
29+
draw_scores: bool = False,
2930
) -> np.ndarray:
3031
"""
3132
Draw the points included in a list of Detections or TrackedObjects.
@@ -61,6 +62,9 @@ def draw_points(
6162
draw_labels : bool, optional
6263
If set to True, the label is added to a title that is drawn on top of the box.
6364
If an object doesn't have a label this parameter is ignored.
65+
draw_scores : bool, optional
66+
If set to True, the score is added to a title that is drawn on top of the box.
67+
If an object doesn't have a label this parameter is ignored.
6468
text_size : Optional[int], optional
6569
Size of the title, the value is used as a multiplier of the base size of the font.
6670
By default the size is scaled automatically based on the frame size.
@@ -152,10 +156,12 @@ def draw_points(
152156
thickness=thickness,
153157
)
154158

155-
if draw_labels or draw_ids:
159+
if draw_labels or draw_ids or draw_scores:
156160
position = d.points[d.live_points].mean(axis=0)
157161
position -= radius
158-
text = _build_text(d, draw_labels=draw_labels, draw_ids=draw_ids)
162+
text = _build_text(
163+
d, draw_labels=draw_labels, draw_ids=draw_ids, draw_scores=draw_scores
164+
)
159165

160166
Drawer.text(
161167
frame,
@@ -165,6 +171,7 @@ def draw_points(
165171
color=obj_text_color,
166172
thickness=text_thickness,
167173
)
174+
168175
return frame
169176

170177

norfair/drawing/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ def _centroid(tracked_points: np.ndarray) -> Tuple[int, int]:
1313
return int(sum_x / num_points), int(sum_y / num_points)
1414

1515

16-
def _build_text(drawable: "Drawable", draw_labels, draw_ids):
16+
def _build_text(drawable: "Drawable", draw_labels, draw_ids, draw_scores):
1717
text = ""
1818
if draw_labels and drawable.label is not None:
1919
text = str(drawable.label)
2020
if draw_ids and drawable.id is not None:
2121
if len(text) > 0:
2222
text += "-"
2323
text += str(drawable.id)
24+
if draw_scores and drawable.scores is not None:
25+
if len(text) > 0:
26+
text += "-"
27+
text += str(np.round(np.mean(drawable.scores), 4))
2428
return text

0 commit comments

Comments
 (0)