Spaces:
Sleeping
Sleeping
# live_review.py | |
import cv2 | |
import numpy as np | |
import tempfile | |
from utils import analyze_frame_sequence, overlay_annotations, make_decision | |
def analyze_live_video(video): | |
cap = cv2.VideoCapture(video) | |
frames = [] | |
while True: | |
ret, frame = cap.read() | |
if not ret: | |
break | |
frames.append(frame) | |
cap.release() | |
recent_frames = frames[-30:] if len(frames) > 30 else frames | |
analysis = analyze_frame_sequence(recent_frames) | |
decision, reason = make_decision(analysis) | |
annotated_frames = overlay_annotations(recent_frames, analysis) | |
output_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name | |
h, w = recent_frames[0].shape[:2] | |
out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), 20.0, (w, h)) | |
for f in annotated_frames: | |
out.write(f) | |
out.release() | |
return decision, reason, output_path | |