Spaces:
Sleeping
Sleeping
Create video_processor.py
Browse files- video_processor.py +27 -0
video_processor.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import os
|
| 3 |
+
import tempfile
|
| 4 |
+
from detector import LBWDetector
|
| 5 |
+
from utils import draw_boxes
|
| 6 |
+
|
| 7 |
+
def process_video(video_path, output_path="output.mp4"):
|
| 8 |
+
detector = LBWDetector()
|
| 9 |
+
cap = cv2.VideoCapture(video_path)
|
| 10 |
+
|
| 11 |
+
width = int(cap.get(3))
|
| 12 |
+
height = int(cap.get(4))
|
| 13 |
+
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 14 |
+
|
| 15 |
+
out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height))
|
| 16 |
+
|
| 17 |
+
while cap.isOpened():
|
| 18 |
+
ret, frame = cap.read()
|
| 19 |
+
if not ret:
|
| 20 |
+
break
|
| 21 |
+
detections, class_names = detector.detect_objects(frame)
|
| 22 |
+
frame = draw_boxes(frame, detections, class_names)
|
| 23 |
+
out.write(frame)
|
| 24 |
+
|
| 25 |
+
cap.release()
|
| 26 |
+
out.release()
|
| 27 |
+
return output_path
|