Spaces:
Sleeping
Sleeping
File size: 1,123 Bytes
ec7c037 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import cv2
import os
from draw_utils import draw_trajectory
import uuid
def process_video(video_path):
cap = cv2.VideoCapture(video_path)
frames = []
impact_frame = None
trajectory = []
frame_count = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
# Simulated detection (replace with real ML model or logic)
if 20 < frame_count < 80: # Simulate ball in motion
trajectory.append((100 + frame_count, 200 + int(frame_count * 0.2))) # fake curve
if frame_count == 70:
impact_frame = frame.copy()
frames.append(frame)
frame_count += 1
cap.release()
# Draw trajectory
pred_path = f"pred_{uuid.uuid4().hex}.mp4"
draw_trajectory(frames, trajectory, pred_path)
# Save impact frame for analysis
analysis_data = {
"trajectory": trajectory,
"impact_frame": impact_frame
}
replay_path = f"replay_{uuid.uuid4().hex}.mp4"
draw_trajectory(frames, trajectory, replay_path, replay=True)
return pred_path, replay_path, analysis_data
|