dschandra commited on
Commit
d733ee8
·
verified ·
1 Parent(s): 287eb27

Update video_processor.py

Browse files
Files changed (1) hide show
  1. video_processor.py +6 -31
video_processor.py CHANGED
@@ -1,5 +1,6 @@
1
  import cv2
2
- import numpy as np
 
3
  from detector import LBWDetector
4
  from utils import draw_boxes, overlay_decision_text
5
 
@@ -13,43 +14,17 @@ def process_video(video_path, output_path="output.mp4"):
13
 
14
  out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height))
15
 
16
- impact_frame = None
17
- impact_point = None
18
- hit_stumps = False
19
-
20
  while cap.isOpened():
21
  ret, frame = cap.read()
22
  if not ret:
23
  break
24
-
25
  detections, class_names = detector.detect_objects(frame)
26
- labels = [class_names[int(cls_id)] for *_, cls_id in detections]
27
-
28
- # Draw overlays
29
  frame = draw_boxes(frame, detections, class_names)
30
-
31
- # Detect impact frame
32
- if 'pad' in labels and 'ball' in labels:
33
- impact_frame = frame.copy()
34
- # Assume impact point is ball's center in this frame
35
- for x1, y1, x2, y2, conf, cls_id in detections:
36
- if class_names[int(cls_id)] == 'ball':
37
- impact_point = ((x1 + x2) / 2, (y1 + y2) / 2)
38
- break
39
-
40
- # Check if ball is later detected near stumps
41
- if 'stumps' in labels and 'ball' in labels:
42
- hit_stumps = True
43
-
44
  out.write(frame)
45
 
46
  cap.release()
47
-
48
- # Append decision screen frame
49
- decision_frame = np.zeros((height, width, 3), dtype=np.uint8)
50
- decision_frame = overlay_decision_text(decision_frame, impact_point, hit_stumps, impact_frame is not None)
51
- for _ in range(int(fps * 2)): # show for 2 seconds
52
- out.write(decision_frame)
53
-
54
  out.release()
55
- return output_path
 
1
  import cv2
2
+ import os
3
+ import tempfile
4
  from detector import LBWDetector
5
  from utils import draw_boxes, overlay_decision_text
6
 
 
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
+ # Placeholder decision; replace with actual LBW logic later
24
+ decision = "Pending" # Example: "Out" or "Not Out"
25
+ frame = overlay_decision_text(frame, decision)
 
 
 
 
 
 
 
 
 
 
 
26
  out.write(frame)
27
 
28
  cap.release()
 
 
 
 
 
 
 
29
  out.release()
30
+ return output_path