Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import cv2
|
2 |
import numpy as np
|
3 |
import torch
|
@@ -99,7 +100,7 @@ def estimate_trajectory(ball_positions, detection_frames, frames):
|
|
99 |
return None, None, None, None, None, None, f"Error in trajectory interpolation: {str(e)}"
|
100 |
|
101 |
vis_trajectory = list(zip(x_coords, y_coords))
|
102 |
-
t_full = np.linspace(times[0], times[-1] + 0.5, len(times) + 5)
|
103 |
x_full = fx(t_full)
|
104 |
y_full = fy(t_full)
|
105 |
full_trajectory = list(zip(x_full, y_full))
|
@@ -144,7 +145,7 @@ def lbw_decision(ball_positions, full_trajectory, frames, pitch_point, impact_po
|
|
144 |
return f"Out (Ball hits stumps, Pitch at x: {pitch_x:.1f}, y: {pitch_y:.1f}, Impact at x: {impact_x:.1f}, y: {impact_y:.1f})", full_trajectory, pitch_point, impact_point
|
145 |
return f"Not Out (Missing stumps, Pitch at x: {pitch_x:.1f}, y: {pitch_y:.1f}, Impact at x: {impact_x:.1f}, y: {impact_y:.1f})", full_trajectory, pitch_point, impact_point
|
146 |
|
147 |
-
def generate_slow_motion(frames, vis_trajectory, pitch_point, pitch_frame, impact_point, impact_frame, detection_frames, output_path):
|
148 |
if not frames:
|
149 |
return None
|
150 |
frame_height, frame_width = frames[0].shape[:2]
|
@@ -183,7 +184,7 @@ def generate_slow_motion(frames, vis_trajectory, pitch_point, pitch_frame, impac
|
|
183 |
cv2.putText(frame, "Impact Factor", (int(x) + 10, int(y) + 20),
|
184 |
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1)
|
185 |
|
186 |
-
if impact_point and i == impact_frame and "Out" in
|
187 |
cv2.putText(frame, "Wicket Factor", (int(stumps_x) - 50, int(stumps_y) - 20),
|
188 |
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 165, 255), 1)
|
189 |
|
@@ -200,7 +201,7 @@ def drs_review(video):
|
|
200 |
decision, full_trajectory, pitch_point, impact_point = lbw_decision(ball_positions, full_trajectory, frames, pitch_point, impact_point)
|
201 |
|
202 |
output_path = f"output_{uuid.uuid4()}.mp4"
|
203 |
-
slow_motion_path = generate_slow_motion(frames, vis_trajectory, pitch_point, pitch_frame, impact_point, impact_frame, detection_frames, output_path)
|
204 |
|
205 |
debug_output = f"{debug_log}\n{trajectory_log}"
|
206 |
return f"DRS Decision: {decision}\nDebug Log:\n{debug_output}", slow_motion_path
|
@@ -218,4 +219,4 @@ iface = gr.Interface(
|
|
218 |
)
|
219 |
|
220 |
if __name__ == "__main__":
|
221 |
-
iface.launch()
|
|
|
1 |
+
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
import torch
|
|
|
100 |
return None, None, None, None, None, None, f"Error in trajectory interpolation: {str(e)}"
|
101 |
|
102 |
vis_trajectory = list(zip(x_coords, y_coords))
|
103 |
+
t_full = np.linspace(times[0], times[-1] + 0.5, len(times) + 5)
|
104 |
x_full = fx(t_full)
|
105 |
y_full = fy(t_full)
|
106 |
full_trajectory = list(zip(x_full, y_full))
|
|
|
145 |
return f"Out (Ball hits stumps, Pitch at x: {pitch_x:.1f}, y: {pitch_y:.1f}, Impact at x: {impact_x:.1f}, y: {impact_y:.1f})", full_trajectory, pitch_point, impact_point
|
146 |
return f"Not Out (Missing stumps, Pitch at x: {pitch_x:.1f}, y: {pitch_y:.1f}, Impact at x: {impact_x:.1f}, y: {impact_y:.1f})", full_trajectory, pitch_point, impact_point
|
147 |
|
148 |
+
def generate_slow_motion(frames, vis_trajectory, pitch_point, pitch_frame, impact_point, impact_frame, detection_frames, output_path, decision):
|
149 |
if not frames:
|
150 |
return None
|
151 |
frame_height, frame_width = frames[0].shape[:2]
|
|
|
184 |
cv2.putText(frame, "Impact Factor", (int(x) + 10, int(y) + 20),
|
185 |
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1)
|
186 |
|
187 |
+
if impact_point and i == impact_frame and "Out" in decision:
|
188 |
cv2.putText(frame, "Wicket Factor", (int(stumps_x) - 50, int(stumps_y) - 20),
|
189 |
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 165, 255), 1)
|
190 |
|
|
|
201 |
decision, full_trajectory, pitch_point, impact_point = lbw_decision(ball_positions, full_trajectory, frames, pitch_point, impact_point)
|
202 |
|
203 |
output_path = f"output_{uuid.uuid4()}.mp4"
|
204 |
+
slow_motion_path = generate_slow_motion(frames, vis_trajectory, pitch_point, pitch_frame, impact_point, impact_frame, detection_frames, output_path, decision)
|
205 |
|
206 |
debug_output = f"{debug_log}\n{trajectory_log}"
|
207 |
return f"DRS Decision: {decision}\nDebug Log:\n{debug_output}", slow_motion_path
|
|
|
219 |
)
|
220 |
|
221 |
if __name__ == "__main__":
|
222 |
+
iface.launch()
|