dschandra commited on
Commit
337c929
·
verified ·
1 Parent(s): 1031306

Create live_review.py

Browse files
Files changed (1) hide show
  1. live_review.py +30 -0
live_review.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # live_review.py
2
+
3
+ import cv2
4
+ import numpy as np
5
+ import tempfile
6
+ from utils import analyze_frame_sequence, overlay_annotations, make_decision
7
+
8
+ def analyze_live_video(video):
9
+ cap = cv2.VideoCapture(video)
10
+ frames = []
11
+ while True:
12
+ ret, frame = cap.read()
13
+ if not ret:
14
+ break
15
+ frames.append(frame)
16
+ cap.release()
17
+
18
+ recent_frames = frames[-30:] if len(frames) > 30 else frames
19
+ analysis = analyze_frame_sequence(recent_frames)
20
+ decision, reason = make_decision(analysis)
21
+
22
+ annotated_frames = overlay_annotations(recent_frames, analysis)
23
+ output_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
24
+ h, w = recent_frames[0].shape[:2]
25
+ out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), 20.0, (w, h))
26
+ for f in annotated_frames:
27
+ out.write(f)
28
+ out.release()
29
+
30
+ return decision, reason, output_path