Spaces:
Sleeping
Sleeping
Update services/overlay_service.py
Browse files- services/overlay_service.py +18 -12
services/overlay_service.py
CHANGED
@@ -1,16 +1,22 @@
|
|
|
|
1 |
import cv2
|
2 |
|
3 |
-
def
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
cv2.rectangle(frame, (x_min, y_min), (x_max, y_max), color, 2)
|
15 |
-
cv2.putText(frame, label, (x_min, y_min - 10),
|
|
|
16 |
return frame
|
|
|
1 |
+
# services/overlay_service.py
|
2 |
import cv2
|
3 |
|
4 |
+
def add_overlay(frame, detections):
|
5 |
+
"""
|
6 |
+
Add overlays (bounding boxes and labels) to a frame.
|
7 |
+
Args:
|
8 |
+
frame: Input frame (numpy array)
|
9 |
+
detections: List of detection dictionaries
|
10 |
+
Returns:
|
11 |
+
numpy array: Frame with overlays
|
12 |
+
"""
|
13 |
+
for detection in detections:
|
14 |
+
if "coordinates" not in detection or "label" not in detection:
|
15 |
+
continue
|
16 |
+
x_min, y_min, x_max, y_max = detection["coordinates"]
|
17 |
+
label = detection["label"]
|
18 |
+
color = (0, 255, 0) # Green for generic overlays
|
19 |
cv2.rectangle(frame, (x_min, y_min), (x_max, y_max), color, 2)
|
20 |
+
cv2.putText(frame, label, (x_min, y_min - 10),
|
21 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
|
22 |
return frame
|