Spaces:
Sleeping
Sleeping
Create utils.py
Browse files
utils.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
def draw_boxes(frame, detections, class_names):
|
5 |
+
for x1, y1, x2, y2, conf, cls_id in detections:
|
6 |
+
label = class_names[int(cls_id)]
|
7 |
+
color = (0, 255, 0) if label == 'ball' else (255, 0, 0)
|
8 |
+
cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)), color, 2)
|
9 |
+
cv2.putText(frame, f"{label} {conf:.2f}", (int(x1), int(y1) - 5),
|
10 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2)
|
11 |
+
return frame
|