Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -1,27 +1,63 @@
|
|
1 |
# utils.py
|
2 |
|
|
|
|
|
|
|
3 |
def analyze_frame_sequence(frames):
|
4 |
-
|
5 |
-
analysis = {
|
6 |
"pitch": "in line",
|
7 |
"impact": "in line",
|
8 |
"trajectory": "hitting",
|
|
|
9 |
}
|
10 |
-
return analysis
|
11 |
|
12 |
def make_decision(analysis):
|
13 |
if analysis['pitch'] == 'outside leg':
|
14 |
-
return "NOT OUT", "
|
15 |
-
if analysis['impact'] == 'outside off':
|
16 |
-
return "NOT OUT", "Impact outside off
|
17 |
if analysis['trajectory'] == 'missing':
|
18 |
-
return "NOT OUT", "Ball missing stumps"
|
19 |
if analysis['trajectory'] == 'umpires call':
|
20 |
-
return "
|
21 |
-
return "OUT", "
|
22 |
-
|
23 |
-
def
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# utils.py
|
2 |
|
3 |
+
import cv2
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
def analyze_frame_sequence(frames):
|
7 |
+
return {
|
|
|
8 |
"pitch": "in line",
|
9 |
"impact": "in line",
|
10 |
"trajectory": "hitting",
|
11 |
+
"shot_offered": True
|
12 |
}
|
|
|
13 |
|
14 |
def make_decision(analysis):
|
15 |
if analysis['pitch'] == 'outside leg':
|
16 |
+
return "NOT OUT", "Pitched outside leg stump."
|
17 |
+
if analysis['impact'] == 'outside off' and analysis['shot_offered']:
|
18 |
+
return "NOT OUT", "Impact outside off with shot offered."
|
19 |
if analysis['trajectory'] == 'missing':
|
20 |
+
return "NOT OUT", "Ball missing stumps."
|
21 |
if analysis['trajectory'] == 'umpires call':
|
22 |
+
return "UMPIRE’S CALL", "Marginal trajectory impact."
|
23 |
+
return "OUT", "Impact in line and ball hitting stumps."
|
24 |
+
|
25 |
+
def overlay_text(frame, text, pos, size=1.0, color=(255,255,255)):
|
26 |
+
cv2.putText(frame, text, pos, cv2.FONT_HERSHEY_SIMPLEX, size, color, 2, cv2.LINE_AA)
|
27 |
+
|
28 |
+
def render_annotated_clip(frames, analysis, decision, reason, output_path):
|
29 |
+
h, w = frames[0].shape[:2]
|
30 |
+
out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), 20.0, (w, h))
|
31 |
+
|
32 |
+
# First 1s: Verdict card
|
33 |
+
verdict_card = np.zeros_like(frames[0])
|
34 |
+
overlay_text(verdict_card, f"FINAL DECISION: {decision}", (50, 200), 2.0, (255,255,255))
|
35 |
+
overlay_text(verdict_card, reason, (50, 250), 0.9, (200,200,200))
|
36 |
+
for _ in range(20):
|
37 |
+
out.write(verdict_card)
|
38 |
+
|
39 |
+
# Main Replay: real-time
|
40 |
+
for i, f in enumerate(frames):
|
41 |
+
overlay_text(f, f"Pitch: {analysis['pitch'].capitalize()}", (30, 50), 0.8, (0,255,0) if analysis['pitch']=="in line" else (0,0,255))
|
42 |
+
overlay_text(f, f"Impact: {analysis['impact'].capitalize()}", (30, 90), 0.8, (0,255,0) if analysis['impact']=="in line" else (0,0,255))
|
43 |
+
overlay_text(f, f"Trajectory: {analysis['trajectory'].capitalize()}", (30, 130), 0.8, (0,255,0) if analysis['trajectory']=="hitting" else (0,0,255))
|
44 |
+
overlay_text(f, f"Shot Offered: {'✓' if analysis['shot_offered'] else '✗'}", (30, 170), 0.8, (0,255,0) if analysis['shot_offered'] else (0,0,255))
|
45 |
+
overlay_text(f, "ICC LBW Review • Third-Umpire Analysis", (30, h - 30), 0.6, (180,180,180))
|
46 |
+
out.write(f)
|
47 |
+
|
48 |
+
# Slow-motion replay (every 2nd frame repeated)
|
49 |
+
for i in range(0, len(frames), 2):
|
50 |
+
f = frames[i].copy()
|
51 |
+
overlay_text(f, f"Pitch: {analysis['pitch'].capitalize()}", (30, 50), 0.8, (0,255,0) if analysis['pitch']=="in line" else (0,0,255))
|
52 |
+
overlay_text(f, f"Impact: {analysis['impact'].capitalize()}", (30, 90), 0.8, (0,255,0) if analysis['impact']=="in line" else (0,0,255))
|
53 |
+
overlay_text(f, f"Trajectory: {analysis['trajectory'].capitalize()}", (30, 130), 0.8, (0,255,0) if analysis['trajectory']=="hitting" else (0,0,255))
|
54 |
+
overlay_text(f, f"Shot Offered: {'✓' if analysis['shot_offered'] else '✗'}", (30, 170), 0.8, (0,255,0) if analysis['shot_offered'] else (0,0,255))
|
55 |
+
overlay_text(f, "ICC LBW Review • Third-Umpire Analysis", (30, h - 30), 0.6, (180,180,180))
|
56 |
+
out.write(f)
|
57 |
+
out.write(f)
|
58 |
+
|
59 |
+
# End frame 0.5s static
|
60 |
+
for _ in range(10):
|
61 |
+
out.write(verdict_card)
|
62 |
+
|
63 |
+
out.release()
|