Spaces:
Sleeping
Sleeping
Update video_processor.py
Browse files- video_processor.py +6 -10
video_processor.py
CHANGED
@@ -15,21 +15,18 @@ def process_video(video_path, output_path="output.mp4"):
|
|
15 |
|
16 |
out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height))
|
17 |
|
18 |
-
# Assume stumps are in the center third of the frame (adjust as needed)
|
19 |
stump_zone = (width // 3, 2 * width // 3)
|
20 |
-
final_decision = "Not Out"
|
21 |
|
22 |
while cap.isOpened():
|
23 |
ret, frame = cap.read()
|
24 |
if not ret:
|
25 |
break
|
26 |
|
27 |
-
# Detect objects (ball, player/pads)
|
28 |
detections, class_names = detector.detect_objects(frame)
|
29 |
frame = draw_boxes(frame, detections, class_names)
|
30 |
|
31 |
-
|
32 |
-
decision = "Not Out" # Frame-level decision
|
33 |
ball_bbox = None
|
34 |
player_bbox = None
|
35 |
|
@@ -37,20 +34,19 @@ def process_video(video_path, output_path="output.mp4"):
|
|
37 |
label = class_names[int(cls_id)]
|
38 |
if label == "ball":
|
39 |
ball_bbox = (x1, y1, x2, y2)
|
40 |
-
elif label in ["player", "pads"]:
|
41 |
player_bbox = (x1, y1, x2, y2)
|
42 |
|
43 |
if ball_bbox and player_bbox:
|
44 |
ball_x_center = (ball_bbox[0] + ball_bbox[2]) / 2
|
45 |
-
# Check if ball hits player in stump zone
|
46 |
if (stump_zone[0] <= ball_x_center <= stump_zone[1] and
|
47 |
-
ball_bbox[1] < player_bbox[3] and ball_bbox[3] > player_bbox[1]):
|
48 |
decision = "Out"
|
49 |
-
final_decision = "Out"
|
50 |
|
51 |
frame = overlay_decision_text(frame, decision)
|
52 |
out.write(frame)
|
53 |
|
54 |
cap.release()
|
55 |
out.release()
|
56 |
-
return output_path, final_decision
|
|
|
15 |
|
16 |
out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height))
|
17 |
|
|
|
18 |
stump_zone = (width // 3, 2 * width // 3)
|
19 |
+
final_decision = "Not Out"
|
20 |
|
21 |
while cap.isOpened():
|
22 |
ret, frame = cap.read()
|
23 |
if not ret:
|
24 |
break
|
25 |
|
|
|
26 |
detections, class_names = detector.detect_objects(frame)
|
27 |
frame = draw_boxes(frame, detections, class_names)
|
28 |
|
29 |
+
decision = "Not Out"
|
|
|
30 |
ball_bbox = None
|
31 |
player_bbox = None
|
32 |
|
|
|
34 |
label = class_names[int(cls_id)]
|
35 |
if label == "ball":
|
36 |
ball_bbox = (x1, y1, x2, y2)
|
37 |
+
elif label in ["player", "pads"]:
|
38 |
player_bbox = (x1, y1, x2, y2)
|
39 |
|
40 |
if ball_bbox and player_bbox:
|
41 |
ball_x_center = (ball_bbox[0] + ball_bbox[2]) / 2
|
|
|
42 |
if (stump_zone[0] <= ball_x_center <= stump_zone[1] and
|
43 |
+
ball_bbox[1] < player_bbox[3] and ball_bbox[3] > player_bbox[1]):
|
44 |
decision = "Out"
|
45 |
+
final_decision = "Out"
|
46 |
|
47 |
frame = overlay_decision_text(frame, decision)
|
48 |
out.write(frame)
|
49 |
|
50 |
cap.release()
|
51 |
out.release()
|
52 |
+
return output_path, final_decision
|