Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -146,13 +146,23 @@ def estimate_trajectory(ball_positions, frames, detection_frames):
|
|
146 |
|
147 |
trajectory_3d = [pixel_to_3d(x, y, frame_height, frame_width) for x, y in trajectory_2d]
|
148 |
detections_3d = [pixel_to_3d(x, y, frame_height, frame_width) for x, y in filtered_positions]
|
|
|
|
|
149 |
pitch_point_3d = pixel_to_3d(pitch_point[0], pitch_point[1], frame_height, frame_width) if pitch_point else None
|
150 |
impact_point_3d = pixel_to_3d(impact_point[0], impact_point[1], frame_height, frame_width) if impact_point else None
|
151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
debug_log = (
|
153 |
f"Trajectory estimated successfully\n"
|
154 |
-
f"Pitch point at frame {pitch_frame + 1}:
|
155 |
-
f"Impact point at frame {impact_frame + 1}:
|
156 |
f"Detections in frames: {filtered_frames}"
|
157 |
)
|
158 |
return trajectory_2d, pitch_point, impact_point, pitch_frame, impact_frame, detections_3d, trajectory_3d, pitch_point_3d, impact_point_3d, debug_log
|
@@ -328,4 +338,4 @@ iface = gr.Interface(
|
|
328 |
)
|
329 |
|
330 |
if __name__ == "__main__":
|
331 |
-
iface.launch()
|
|
|
146 |
|
147 |
trajectory_3d = [pixel_to_3d(x, y, frame_height, frame_width) for x, y in trajectory_2d]
|
148 |
detections_3d = [pixel_to_3d(x, y, frame_height, frame_width) for x, y in filtered_positions]
|
149 |
+
|
150 |
+
# Handle missing pitch and impact points gracefully
|
151 |
pitch_point_3d = pixel_to_3d(pitch_point[0], pitch_point[1], frame_height, frame_width) if pitch_point else None
|
152 |
impact_point_3d = pixel_to_3d(impact_point[0], impact_point[1], frame_height, frame_width) if impact_point else None
|
153 |
|
154 |
+
# Handle cases where no pitch/impact point is found
|
155 |
+
if pitch_point is None:
|
156 |
+
pitch_frame = "N/A"
|
157 |
+
pitch_point_3d = None # No 3D coordinates for pitch point
|
158 |
+
if impact_point is None:
|
159 |
+
impact_frame = "N/A"
|
160 |
+
impact_point_3d = None # No 3D coordinates for impact point
|
161 |
+
|
162 |
debug_log = (
|
163 |
f"Trajectory estimated successfully\n"
|
164 |
+
f"Pitch point at frame {pitch_frame + 1 if pitch_frame != 'N/A' else 'N/A'}: {pitch_point if pitch_point else 'Not detected'}\n"
|
165 |
+
f"Impact point at frame {impact_frame + 1 if impact_frame != 'N/A' else 'N/A'}: {impact_point if impact_point else 'Not detected'}\n"
|
166 |
f"Detections in frames: {filtered_frames}"
|
167 |
)
|
168 |
return trajectory_2d, pitch_point, impact_point, pitch_frame, impact_frame, detections_3d, trajectory_3d, pitch_point_3d, impact_point_3d, debug_log
|
|
|
338 |
)
|
339 |
|
340 |
if __name__ == "__main__":
|
341 |
+
iface.launch()
|