AjaykumarPilla commited on
Commit
640c086
·
verified ·
1 Parent(s): 885c61f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -16
app.py CHANGED
@@ -19,7 +19,6 @@ CONF_THRESHOLD = 0.25 # Confidence threshold for detection
19
  IMPACT_ZONE_Y = 0.85 # Fraction of frame height for impact zone
20
  PITCH_ZONE_Y = 0.75 # Fraction of frame height for pitch zone
21
  IMPACT_DELTA_Y = 50 # Pixels for detecting sudden y-position change
22
- STUMPS_HEIGHT = 0.711 # meters (height of stumps)
23
 
24
  def process_video(video_path):
25
  if not os.path.exists(video_path):
@@ -143,10 +142,6 @@ def generate_slow_motion(frames, vis_trajectory, pitch_point, pitch_frame, impac
143
  if not frames:
144
  return None
145
  frame_height, frame_width = frames[0].shape[:2]
146
- stumps_x = frame_width / 2
147
- stumps_y = frame_height * 0.9
148
- stumps_width_pixels = frame_width * (STUMPS_WIDTH / 3.0)
149
- stumps_height_pixels = frame_height * (STUMPS_HEIGHT / 3.0)
150
 
151
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
152
  out = cv2.VideoWriter(output_path, fourcc, FRAME_RATE / SLOW_MOTION_FACTOR, (frame_width, frame_height))
@@ -155,15 +150,6 @@ def generate_slow_motion(frames, vis_trajectory, pitch_point, pitch_frame, impac
155
  trajectory_points = np.array(vis_trajectory, dtype=np.int32).reshape((-1, 1, 2))
156
 
157
  for i, frame in enumerate(frames):
158
- # Draw stumps (three white vertical lines)
159
- stump_positions = [
160
- (stumps_x - stumps_width_pixels / 2, stumps_y), # Left stump
161
- (stumps_x, stumps_y), # Middle stump
162
- (stumps_x + stumps_width_pixels / 2, stumps_y) # Right stump
163
- ]
164
- for x, y in stump_positions:
165
- cv2.line(frame, (int(x), int(y)), (int(x), int(y - stumps_height_pixels)), (255, 255, 255), 2)
166
-
167
  # Draw trajectory (blue line) only for detected frames
168
  if i in detection_frames and trajectory_points.size > 0:
169
  idx = detection_frames.index(i) + 1
@@ -208,10 +194,10 @@ iface = gr.Interface(
208
  inputs=gr.Video(label="Upload Video Clip"),
209
  outputs=[
210
  gr.Textbox(label="DRS Decision and Debug Log"),
211
- gr.Video(label="Very Slow-Motion Replay with Ball Detection (Green), Trajectory (Blue Line), Pitch Point (Red), Impact Point (Yellow), Stumps (White)")
212
  ],
213
  title="AI-Powered DRS for LBW in Local Cricket",
214
- description="Upload a video clip of a cricket delivery to get an LBW decision and slow-motion replay showing ball detection (green boxes), trajectory (blue line), pitch point (red circle), impact point (yellow circle), and stumps (white lines)."
215
  )
216
 
217
  if __name__ == "__main__":
 
19
  IMPACT_ZONE_Y = 0.85 # Fraction of frame height for impact zone
20
  PITCH_ZONE_Y = 0.75 # Fraction of frame height for pitch zone
21
  IMPACT_DELTA_Y = 50 # Pixels for detecting sudden y-position change
 
22
 
23
  def process_video(video_path):
24
  if not os.path.exists(video_path):
 
142
  if not frames:
143
  return None
144
  frame_height, frame_width = frames[0].shape[:2]
 
 
 
 
145
 
146
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
147
  out = cv2.VideoWriter(output_path, fourcc, FRAME_RATE / SLOW_MOTION_FACTOR, (frame_width, frame_height))
 
150
  trajectory_points = np.array(vis_trajectory, dtype=np.int32).reshape((-1, 1, 2))
151
 
152
  for i, frame in enumerate(frames):
 
 
 
 
 
 
 
 
 
153
  # Draw trajectory (blue line) only for detected frames
154
  if i in detection_frames and trajectory_points.size > 0:
155
  idx = detection_frames.index(i) + 1
 
194
  inputs=gr.Video(label="Upload Video Clip"),
195
  outputs=[
196
  gr.Textbox(label="DRS Decision and Debug Log"),
197
+ gr.Video(label="Very Slow-Motion Replay with Ball Detection (Green), Trajectory (Blue Line), Pitch Point (Red), Impact Point (Yellow)")
198
  ],
199
  title="AI-Powered DRS for LBW in Local Cricket",
200
+ description="Upload a video clip of a cricket delivery to get an LBW decision and slow-motion replay showing ball detection (green boxes), trajectory (blue line), pitch point (red circle), and impact point (yellow circle)."
201
  )
202
 
203
  if __name__ == "__main__":