lbw_app / video_utils.py
DSatishchandra's picture
Create video_utils.py
ec7c037 verified
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