Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -39,12 +39,10 @@ def overlay_annotations_dynamic(frame, analysis, t):
|
|
39 |
ball_pos = analysis['trajectory_curve'][t]
|
40 |
cv2.circle(frame, ball_pos, 8, (0, 255, 0) if analysis['trajectory'] == 'hitting' else (0, 0, 255), -1)
|
41 |
|
42 |
-
# Draw complete arc
|
43 |
for i in range(1, min(t + 1, len(analysis['trajectory_curve']))):
|
44 |
cv2.line(frame, analysis['trajectory_curve'][i - 1], analysis['trajectory_curve'][i],
|
45 |
(0, 255, 0) if analysis['trajectory'] == 'hitting' else (0, 0, 255), 2)
|
46 |
|
47 |
-
# Highlight stumps zone
|
48 |
x1, y1 = analysis['stump_zone'][0]
|
49 |
x2, y2 = analysis['stump_zone'][1]
|
50 |
overlay = frame.copy()
|
@@ -53,10 +51,8 @@ def overlay_annotations_dynamic(frame, analysis, t):
|
|
53 |
frame[:] = cv2.addWeighted(overlay, alpha, frame, 1 - alpha, 0)
|
54 |
cv2.rectangle(frame, (x1, y1), (x2, y2), (180, 180, 180), 2)
|
55 |
|
56 |
-
# Shot
|
57 |
shot_icon = "✓" if analysis['shot_offered'] else "✗"
|
58 |
overlay_text(frame, f"Shot Offered: {shot_icon}", (30, 170), 0.8, (0,255,0) if analysis['shot_offered'] else (0,0,255))
|
59 |
-
|
60 |
overlay_text(frame, f"Trajectory: {analysis['trajectory'].capitalize()}", (30, 130), 0.8,
|
61 |
(0, 255, 0) if analysis['trajectory'] == 'hitting' else (0, 0, 255))
|
62 |
overlay_text(frame, "ICC LBW Review • Third-Umpire Analysis", (30, frame.shape[0] - 30), 0.6, (180,180,180))
|
@@ -73,39 +69,10 @@ def render_annotated_clip(frames, analysis, decision, reason, output_path):
|
|
73 |
out.write(verdict_card)
|
74 |
|
75 |
# Dynamic replay with animated ball tracking
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
# Draw trajectory arc up to frame t
|
82 |
-
for i in range(1, min(t + 1, len(trajectory_points))):
|
83 |
-
cv2.line(annotated, trajectory_points[i - 1], trajectory_points[i],
|
84 |
-
(0, 255, 0) if analysis['trajectory'] == 'hitting' else (0, 0, 255), 2)
|
85 |
-
|
86 |
-
# Draw current ball position
|
87 |
-
if t < len(trajectory_points):
|
88 |
-
ball_pos = trajectory_points[t]
|
89 |
-
cv2.circle(annotated, ball_pos, 8,
|
90 |
-
(0, 255, 0) if analysis['trajectory'] == 'hitting' else (0, 0, 255), -1)
|
91 |
-
|
92 |
-
# Draw other overlays
|
93 |
-
overlay_text(annotated, "ICC LBW Review • Third-Umpire Analysis", (30, annotated.shape[0] - 30), 0.6, (180, 180, 180))
|
94 |
-
overlay_text(annotated, f"Trajectory: {analysis['trajectory'].capitalize()}", (30, 130), 0.8,
|
95 |
-
(0, 255, 0) if analysis['trajectory'] == 'hitting' else (0, 0, 255))
|
96 |
-
|
97 |
-
# Optional stump zone overlay
|
98 |
-
if 'stump_zone' in analysis:
|
99 |
-
x1, y1 = analysis['stump_zone'][0]
|
100 |
-
x2, y2 = analysis['stump_zone'][1]
|
101 |
-
overlay = annotated.copy()
|
102 |
-
cv2.rectangle(overlay, (x1, y1), (x2, y2), (255, 255, 255), -1)
|
103 |
-
alpha = 0.2
|
104 |
-
annotated[:] = cv2.addWeighted(overlay, alpha, annotated, 1 - alpha, 0)
|
105 |
-
cv2.rectangle(annotated, (x1, y1), (x2, y2), (180, 180, 180), 2)
|
106 |
-
|
107 |
-
out.write(annotated)
|
108 |
-
|
109 |
|
110 |
# Slow-motion: emphasize final 3 points
|
111 |
for pt in analysis['trajectory_curve'][-3:]:
|
@@ -117,30 +84,7 @@ for t, f in enumerate(frames):
|
|
117 |
overlay_text(f, "ICC LBW Review • Third-Umpire Analysis", (30, h - 30), 0.6, (180,180,180))
|
118 |
out.write(f)
|
119 |
|
120 |
-
# End card (0.5s)
|
121 |
for _ in range(10):
|
122 |
out.write(verdict_card)
|
123 |
|
124 |
out.release()
|
125 |
-
|
126 |
-
def overlay_dynamic_tracking(frames, output_path):
|
127 |
-
trajectory_points = [(200 + i * 10, 300 - i * 7) for i in range(min(len(frames), 6))]
|
128 |
-
h, w = frames[0].shape[:2]
|
129 |
-
out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), 20.0, (w, h))
|
130 |
-
|
131 |
-
for i, frame in enumerate(frames):
|
132 |
-
annotated = frame.copy()
|
133 |
-
# Draw previous path
|
134 |
-
for j in range(1, min(i+1, len(trajectory_points))):
|
135 |
-
cv2.line(annotated, trajectory_points[j-1], trajectory_points[j], (0, 255, 0), 2)
|
136 |
-
# Draw ball
|
137 |
-
if i < len(trajectory_points):
|
138 |
-
cv2.circle(annotated, trajectory_points[i], 8, (0, 255, 0), -1)
|
139 |
-
# Optional: Stump zone or labels
|
140 |
-
cv2.putText(annotated, "Ball Tracking Simulation", (30, 40),
|
141 |
-
cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255,255,255), 2)
|
142 |
-
out.write(annotated)
|
143 |
-
|
144 |
-
out.release()
|
145 |
-
return output_path
|
146 |
-
|
|
|
39 |
ball_pos = analysis['trajectory_curve'][t]
|
40 |
cv2.circle(frame, ball_pos, 8, (0, 255, 0) if analysis['trajectory'] == 'hitting' else (0, 0, 255), -1)
|
41 |
|
|
|
42 |
for i in range(1, min(t + 1, len(analysis['trajectory_curve']))):
|
43 |
cv2.line(frame, analysis['trajectory_curve'][i - 1], analysis['trajectory_curve'][i],
|
44 |
(0, 255, 0) if analysis['trajectory'] == 'hitting' else (0, 0, 255), 2)
|
45 |
|
|
|
46 |
x1, y1 = analysis['stump_zone'][0]
|
47 |
x2, y2 = analysis['stump_zone'][1]
|
48 |
overlay = frame.copy()
|
|
|
51 |
frame[:] = cv2.addWeighted(overlay, alpha, frame, 1 - alpha, 0)
|
52 |
cv2.rectangle(frame, (x1, y1), (x2, y2), (180, 180, 180), 2)
|
53 |
|
|
|
54 |
shot_icon = "✓" if analysis['shot_offered'] else "✗"
|
55 |
overlay_text(frame, f"Shot Offered: {shot_icon}", (30, 170), 0.8, (0,255,0) if analysis['shot_offered'] else (0,0,255))
|
|
|
56 |
overlay_text(frame, f"Trajectory: {analysis['trajectory'].capitalize()}", (30, 130), 0.8,
|
57 |
(0, 255, 0) if analysis['trajectory'] == 'hitting' else (0, 0, 255))
|
58 |
overlay_text(frame, "ICC LBW Review • Third-Umpire Analysis", (30, frame.shape[0] - 30), 0.6, (180,180,180))
|
|
|
69 |
out.write(verdict_card)
|
70 |
|
71 |
# Dynamic replay with animated ball tracking
|
72 |
+
for t, f in enumerate(frames):
|
73 |
+
annotated = f.copy()
|
74 |
+
overlay_annotations_dynamic(annotated, analysis, t)
|
75 |
+
out.write(annotated)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
# Slow-motion: emphasize final 3 points
|
78 |
for pt in analysis['trajectory_curve'][-3:]:
|
|
|
84 |
overlay_text(f, "ICC LBW Review • Third-Umpire Analysis", (30, h - 30), 0.6, (180,180,180))
|
85 |
out.write(f)
|
86 |
|
|
|
87 |
for _ in range(10):
|
88 |
out.write(verdict_card)
|
89 |
|
90 |
out.release()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|