File size: 907 Bytes
337c929
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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