AjaykumarPilla commited on
Commit
2c04ca3
·
verified ·
1 Parent(s): 25f8bcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -81,10 +81,17 @@ def estimate_trajectory(ball_positions, frames, detection_frames):
81
  pitch_point = ball_positions[0]
82
  pitch_frame = detection_frames[0]
83
 
 
84
  impact_idx = None
85
  impact_frame = None
86
  for i in range(1, len(y_coords)):
87
- if y_coords[i] > frame_height * IMPACT_ZONE_Y or abs(y_coords[i] - y_coords[i-1]) > IMPACT_DELTA_Y:
 
 
 
 
 
 
88
  impact_idx = i
89
  impact_frame = detection_frames[i]
90
  break
@@ -109,7 +116,13 @@ def estimate_trajectory(ball_positions, frames, detection_frames):
109
  pitch_point_3d = pixel_to_3d(pitch_point[0], pitch_point[1], frame_height, frame_width)
110
  impact_point_3d = pixel_to_3d(impact_point[0], impact_point[1], frame_height, frame_width)
111
 
112
- debug_log = f"Trajectory estimated successfully\nPitch point at frame {pitch_frame + 1}: ({pitch_point[0]:.1f}, {pitch_point[1]:.1f})\nImpact point at frame {impact_frame + 1}: ({impact_point[0]:.1f}, {impact_point[1]:.1f})"
 
 
 
 
 
 
113
  return trajectory_2d, pitch_point, impact_point, pitch_frame, impact_frame, detections_3d, trajectory_3d, pitch_point_3d, impact_point_3d, debug_log
114
 
115
  def lbw_decision(ball_positions, trajectory, frames, pitch_point, impact_point):
@@ -193,7 +206,7 @@ def create_3d_plot(detections_3d, trajectory_3d, pitch_point_3d, impact_point_3d
193
  impact_scatter = go.Scatter3d(
194
  x=[impact_point_3d[0]] if impact_point_3d else [],
195
  y=[impact_point_3d[1]] if impact_point_3d else [],
196
- z=[impact_point_3d[2]] if impact_point_3d else [],
197
  mode='markers', marker=dict(size=8, color='yellow'), name='Impact Point'
198
  )
199
  data = [trajectory_line, pitch_scatter, impact_scatter] + stump_traces + bail_traces
 
81
  pitch_point = ball_positions[0]
82
  pitch_frame = detection_frames[0]
83
 
84
+ # Prioritize sudden y-change for impact detection
85
  impact_idx = None
86
  impact_frame = None
87
  for i in range(1, len(y_coords)):
88
+ delta_y = abs(y_coords[i] - y_coords[i-1])
89
+ if delta_y > IMPACT_DELTA_Y:
90
+ impact_idx = i
91
+ impact_frame = detection_frames[i]
92
+ break
93
+ elif y_coords[i] > frame_height * IMPACT_ZONE_Y:
94
+ # Fallback to y-position if no significant y-change
95
  impact_idx = i
96
  impact_frame = detection_frames[i]
97
  break
 
116
  pitch_point_3d = pixel_to_3d(pitch_point[0], pitch_point[1], frame_height, frame_width)
117
  impact_point_3d = pixel_to_3d(impact_point[0], impact_point[1], frame_height, frame_width)
118
 
119
+ debug_log = (
120
+ f"Trajectory estimated successfully\n"
121
+ f"Pitch point at frame {pitch_frame + 1}: ({pitch_point[0]:.1f}, {pitch_point[1]:.1f})\n"
122
+ f"Impact point at frame {impact_frame + 1}: ({impact_point[0]:.1f}, {impact_point[1]:.1f})\n"
123
+ f"Detections in frames: {detection_frames}\n"
124
+ f"Y-coordinate changes: {[abs(y_coords[i] - y_coords[i-1]) for i in range(1, len(y_coords))]}"
125
+ )
126
  return trajectory_2d, pitch_point, impact_point, pitch_frame, impact_frame, detections_3d, trajectory_3d, pitch_point_3d, impact_point_3d, debug_log
127
 
128
  def lbw_decision(ball_positions, trajectory, frames, pitch_point, impact_point):
 
206
  impact_scatter = go.Scatter3d(
207
  x=[impact_point_3d[0]] if impact_point_3d else [],
208
  y=[impact_point_3d[1]] if impact_point_3d else [],
209
+ z=[impact_point_3d[2]] if pitch_point_3d else [],
210
  mode='markers', marker=dict(size=8, color='yellow'), name='Impact Point'
211
  )
212
  data = [trajectory_line, pitch_scatter, impact_scatter] + stump_traces + bail_traces