Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -93,9 +93,18 @@ def estimate_trajectory_3d(ball_positions, detection_frames, frames):
|
|
93 |
impact_point = (x_coords[impact_idx], y_coords[impact_idx], 0)
|
94 |
impact_frame = detection_frames[impact_idx]
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
t_full = np.linspace(times[0], times[impact_idx] + 0.5, 50)
|
100 |
full_trajectory = list(zip(fx(t_full), fy(t_full), fz(t_full)))
|
101 |
|
|
|
93 |
impact_point = (x_coords[impact_idx], y_coords[impact_idx], 0)
|
94 |
impact_frame = detection_frames[impact_idx]
|
95 |
|
96 |
+
# Use cubic interpolation to avoid derivative mismatch
|
97 |
+
try:
|
98 |
+
fx = interp1d(times[:impact_idx + 1], x_coords[:impact_idx + 1], kind='cubic', fill_value="extrapolate")
|
99 |
+
fy = interp1d(times[:impact_idx + 1], y_coords[:impact_idx + 1], kind='cubic', fill_value="extrapolate")
|
100 |
+
fz = interp1d(times[:impact_idx + 1], z_coords[:impact_idx + 1], kind='cubic', fill_value="extrapolate")
|
101 |
+
except ValueError as e:
|
102 |
+
# Fallback to linear if cubic fails (e.g., too few points)
|
103 |
+
fx = interp1d(times[:impact_idx + 1], x_coords[:impact_idx + 1], kind='linear', fill_value="extrapolate")
|
104 |
+
fy = interp1d(times[:impact_idx + 1], y_coords[:impact_idx + 1], kind='linear', fill_value="extrapolate")
|
105 |
+
fz = interp1d(times[:impact_idx + 1], z_coords[:impact_idx + 1], kind='linear', fill_value="extrapolate")
|
106 |
+
print(f"Warning: Cubic interpolation failed, falling back to linear. Error: {str(e)}")
|
107 |
+
|
108 |
t_full = np.linspace(times[0], times[impact_idx] + 0.5, 50)
|
109 |
full_trajectory = list(zip(fx(t_full), fy(t_full), fz(t_full)))
|
110 |
|