lbw_drs_app / video_processor.py
dschandra's picture
Create video_processor.py
770130f verified
raw
history blame
721 Bytes
import cv2
import os
import tempfile
from detector import LBWDetector
from utils import draw_boxes
def process_video(video_path, output_path="output.mp4"):
detector = LBWDetector()
cap = cv2.VideoCapture(video_path)
width = int(cap.get(3))
height = int(cap.get(4))
fps = cap.get(cv2.CAP_PROP_FPS)
out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height))
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
detections, class_names = detector.detect_objects(frame)
frame = draw_boxes(frame, detections, class_names)
out.write(frame)
cap.release()
out.release()
return output_path