Spaces:
Runtime error
Runtime error
Update services/video_service.py
Browse files- services/video_service.py +29 -7
services/video_service.py
CHANGED
|
@@ -1,9 +1,31 @@
|
|
| 1 |
import cv2
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import cv2
|
| 2 |
+
import random
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# List of all videos available for cycling
|
| 6 |
+
VIDEO_FOLDER = "data"
|
| 7 |
+
VIDEO_FILES = [
|
| 8 |
+
"drone_day.mp4",
|
| 9 |
+
"thermal_hotspot.mp4",
|
| 10 |
+
"shadow_dust_issue.mp4",
|
| 11 |
+
"night_intrusion.mp4",
|
| 12 |
+
"alert_response.mp4"
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
video_paths = [os.path.join(VIDEO_FOLDER, video) for video in VIDEO_FILES]
|
| 16 |
+
|
| 17 |
+
def get_random_video_frame():
|
| 18 |
+
while True:
|
| 19 |
+
video_path = random.choice(video_paths)
|
| 20 |
+
cap = cv2.VideoCapture(video_path)
|
| 21 |
+
|
| 22 |
+
if not cap.isOpened():
|
| 23 |
+
continue # skip invalid file
|
| 24 |
+
|
| 25 |
+
while cap.isOpened():
|
| 26 |
+
ret, frame = cap.read()
|
| 27 |
+
if not ret:
|
| 28 |
+
break
|
| 29 |
+
yield frame, os.path.basename(video_path)
|
| 30 |
+
|
| 31 |
+
cap.release()
|