Spaces:
Runtime error
Runtime error
Update services/video_service.py
Browse files- services/video_service.py +27 -18
services/video_service.py
CHANGED
|
@@ -21,24 +21,33 @@ class VideoService:
|
|
| 21 |
return Image.fromarray(frame_rgb)
|
| 22 |
|
| 23 |
def draw_detections(self, frame, detections):
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def save_video(self, frames, output_path, fps=30):
|
| 44 |
"""Save frames as a video."""
|
|
|
|
| 21 |
return Image.fromarray(frame_rgb)
|
| 22 |
|
| 23 |
def draw_detections(self, frame, detections):
|
| 24 |
+
frame_copy = frame.copy()
|
| 25 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 26 |
+
cv2.putText(
|
| 27 |
+
frame_copy,
|
| 28 |
+
timestamp,
|
| 29 |
+
(10, 30),
|
| 30 |
+
cv2.FONT_HERSHEY_SIMPLEX,
|
| 31 |
+
1,
|
| 32 |
+
(255, 255, 255),
|
| 33 |
+
2
|
| 34 |
+
)
|
| 35 |
+
for detection in detections:
|
| 36 |
+
score = detection["score"]
|
| 37 |
+
label = detection["label"]
|
| 38 |
+
box = detection["box"]
|
| 39 |
+
x1, y1, x2, y2 = box["xmin"], box["ymin"], box["xmax"], box["ymax"]
|
| 40 |
+
cv2.rectangle(frame_copy, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 41 |
+
cv2.putText(
|
| 42 |
+
frame_copy,
|
| 43 |
+
f"{label}: {score:.2f}",
|
| 44 |
+
(x1, y1 - 10),
|
| 45 |
+
cv2.FONT_HERSHEY_SIMPLEX,
|
| 46 |
+
0.5,
|
| 47 |
+
(0, 255, 0),
|
| 48 |
+
2
|
| 49 |
+
)
|
| 50 |
+
return frame_copy
|
| 51 |
|
| 52 |
def save_video(self, frames, output_path, fps=30):
|
| 53 |
"""Save frames as a video."""
|