AjaykumarPilla commited on
Commit
672e669
·
verified ·
1 Parent(s): 7b4b7ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -28,6 +28,7 @@ MODEL_INPUT_SIZE = (640, 640) # (height, width)
28
  FRAME_SKIP = 2 # Process every 2nd frame
29
  MIN_DETECTIONS = 10 # Stop after 10 detections
30
  BATCH_SIZE = 4 # Process 4 frames at a time
 
31
 
32
  # Load model
33
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@@ -181,7 +182,7 @@ def estimate_speed(positions, frame_numbers, frame_rate, frame_width):
181
  avg_speed_kmh = np.mean(speeds) * 3.6
182
  return avg_speed_kmh, "Speed calculated successfully"
183
 
184
- # Main Gradio function with video overlay
185
  def drs_analysis(video):
186
  # Video is a file path (string) in Hugging Face Spaces
187
  video_path = video if isinstance(video, str) else "temp_video.mp4"
@@ -202,7 +203,7 @@ def drs_analysis(video):
202
  pitch_x, pitch_y = map_pitch(bounce_point, frame_width, frame_height)
203
  speed_kmh, speed_status = estimate_speed(positions, frame_numbers, frame_rate, frame_width)
204
 
205
- # Create output video with overlays
206
  output_path = "output_video.mp4"
207
  cap = cv2.VideoCapture(video_path)
208
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
@@ -257,7 +258,10 @@ def drs_analysis(video):
257
  text = f"LBW: {lbw_decision}\nSpeed: {speed_kmh:.2f} km/h"
258
  cv2.putText(frame, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
259
 
260
- out.write(frame)
 
 
 
261
  frame_count += 1
262
 
263
  cap.release()
 
28
  FRAME_SKIP = 2 # Process every 2nd frame
29
  MIN_DETECTIONS = 10 # Stop after 10 detections
30
  BATCH_SIZE = 4 # Process 4 frames at a time
31
+ SLOW_MOTION_FACTOR = 3 # Duplicate each frame 3 times for slow motion
32
 
33
  # Load model
34
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
182
  avg_speed_kmh = np.mean(speeds) * 3.6
183
  return avg_speed_kmh, "Speed calculated successfully"
184
 
185
+ # Main Gradio function with video overlay and slow motion
186
  def drs_analysis(video):
187
  # Video is a file path (string) in Hugging Face Spaces
188
  video_path = video if isinstance(video, str) else "temp_video.mp4"
 
203
  pitch_x, pitch_y = map_pitch(bounce_point, frame_width, frame_height)
204
  speed_kmh, speed_status = estimate_speed(positions, frame_numbers, frame_rate, frame_width)
205
 
206
+ # Create output video with overlays and slow motion
207
  output_path = "output_video.mp4"
208
  cap = cv2.VideoCapture(video_path)
209
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
 
258
  text = f"LBW: {lbw_decision}\nSpeed: {speed_kmh:.2f} km/h"
259
  cv2.putText(frame, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
260
 
261
+ # Write frame multiple times for slow motion
262
+ for _ in range(SLOW_MOTION_FACTOR):
263
+ out.write(frame)
264
+
265
  frame_count += 1
266
 
267
  cap.release()