Skip to content

Commit a07463b

Browse files
Display object tracking IDs and labels on video frames using OpenCV (#30)
1 parent ec54fac commit a07463b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

examples/image/classify-video.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ def getFrame(sec):
9292
print('\t%s (%.2f): x=%d y=%d w=%d h=%d' % (bb['label'], bb['value'], bb['x'], bb['y'], bb['width'], bb['height']))
9393
img = cv2.rectangle(cropped, (bb['x'], bb['y']), (bb['x'] + bb['width'], bb['y'] + bb['height']), (255, 0, 0), 1)
9494

95+
# Object tracking output
96+
if "object_tracking" in res["result"].keys():
97+
print('Found %d tracked objects' % (len(res["result"]["object_tracking"])))
98+
for obj in res["result"]["object_tracking"]:
99+
print('\tID=%s, label=%s, value=%.2f, x=%d, y=%d, w=%d, h=%d' % (
100+
obj['object_id'], obj['label'], obj['value'], obj['x'], obj['y'], obj['width'], obj['height']))
101+
# Draw bounding box
102+
x = obj['x']
103+
y = obj['y']
104+
w = obj['width']
105+
h = obj['height']
106+
img = cv2.rectangle(cropped, (x, y), (x + w, y + h), (0, 255, 0), 2)
107+
# Draw label and ID
108+
label_id_text = f"ID={obj['object_id']}, {obj['label']}"
109+
text_x = x
110+
text_y = y - 10 if y - 10 > 10 else y + 20
111+
img = cv2.putText(img, label_id_text, (text_x, text_y),
112+
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
113+
95114
if "visual_anomaly_grid" in res["result"].keys():
96115
print('Found %d visual anomalies (%d ms.)' % (len(res["result"]["visual_anomaly_grid"]), res['timing']['dsp'] +
97116
res['timing']['classification'] +

0 commit comments

Comments
 (0)