Tennis AI Coach
Swift · Computer Vision · On-device ML
An on-device computer vision app that analyzes tennis serves in real time. The app detects body keypoints and ball trajectories, thereby measuring the serve speed, and generating concise techique tips.
Demo: on-device serve analysis and speed estimation
Serve speed
Estimates velocity from ball trajectories observed across frames and overlays results in real time
Technique feedback
Analyzes your serve to detect the trophy pose and the moment of contact, surfacing concise, actionable feedback on how to improve your serve
Technical implementation details
- Pose estimation pipeline: Apple Vision’s
VNHumanBodyPoseObservationwith custom temporal smoothing to stabilize joint keypoints and detect serve phases (trophy pose and contact) across frame sequences - Trajectory analysis: Real-time ball tracking via
VNDetectTrajectoriesRequest, using frame differentials and polynomial coefficient filters (parabolic fits, left-to-right validation, confidence thresholds >0.6) to isolate valid serve trajectories - Speed computation: Serve velocity derived from frame timestamps, trajectory length, and duration windows; parabolic extrapolation fills early path segments to increase precision before contact
- Overlay architecture: Frame-accurate overlays rendered through a SwiftUI/UIView hybrid, with a custom
TrajectoryViewfor path rendering andUILabel-driven real-time speed feedback - AI coaching logic: Custom
AICoachclass applies geometric heuristics (e.g., joint angle calculations, elbow-over-shoulder thresholds, wrist height derivatives) to detect suboptimal mechanics and output rule-based feedback prompts - On-device design: Entire inference and feedback loop runs locally (AVFoundation + Vision), optimizing for low-latency analysis, privacy, and offline usability