π Turning raw match footage into a live tactical radar using computer vision β½
Duel Vision is a computer vision pipeline built to analyze UC Davis women's soccer match footage. Given a single video file, it detects players, goalkeepers, referees, and the ball, tracks each player across the full match, automatically sorts players into teams by jersey color, and projects everyone's position onto a 2D bird's-eye radar view of the pitch, all without any manual labeling of teams or players.
π How It Works
1. π Detection
Three custom-trained YOLO models handle the core perception work:
| Model | What It Does |
|---|---|
football-player-detection.pt | Detects players, goalkeepers, and referees in each frame |
football-ball-detection.pt | A specialized ball-only detector that runs on sliced 640Γ640 tiles (via SAHI) to catch the ball even at small scale |
football-pitch-detection.pt | A keypoint detector that finds pitch landmarks β corners, penalty boxes, the center circle, which is used later for the radar projection |
2. π Tracking
Once players are detected, ByteTrack assigns each one a persistent tracker ID, requiring three consecutive frames before confirming a new track. That ID stays stable across the whole match, even through brief occlusions or players bunching up near the ball.
3. π¨ Team Classification
Rather than relying on pose estimation or jersey numbers, Duel Vision classifies teams purely from jersey color:
- Crop collection β high-confidence player detections are cropped from sampled frames, then cropped again down to the torso (roughly the middle 15β55% vertically, 15β85% horizontally) to isolate the jersey and avoid noise from faces, hair, and shorts.
- Feature extraction β a 24-bin HSV color histogram (16 hue bins + 8 saturation bins) is computed for each jersey crop, ignoring low-saturation pixels so skin tones and background grass don't get mixed in.
- Dimensionality reduction β PCA compresses each 24-dimensional histogram down to 3 components.
- Clustering β KMeans splits the projected crops into two clusters, one per team.
- Referee detection β any player whose jersey color sits far from both cluster centroids (more than 2.5 standard deviations away) gets flagged as a referee instead of being forced into a team.
4. π§Ή Smoothing
Raw per-frame predictions flicker β a player might get misclassified for a frame or two. Three majority-vote smoothers clean this up:
- TeamVoter keeps a rolling 50-frame window of team predictions per tracker ID. Once a tracker racks up 40+ votes with at least 82% agreement, its team is locked in permanently.
- ClassVoter does the same for the player-vs-referee decision over a 30-frame window.
- OutlierVoter only flags someone as a referee if 70%+ of their recent frames were flagged as outliers, so one bad crop can't mislabel a real player.
5. πΊοΈ Radar View
The radar mode overlays a 2D bird's-eye pitch diagram at the bottom of the video. Each player's position is projected onto that diagram with a homography matrix computed from the pitch keypoints detected in that frame. If fewer than 4 confident keypoints are found, the frame shows an empty pitch rather than a distorted transform.
6. π₯ Duel Detection & Analytics
Duel Vision gets its name from its duel-detection layer, the piece that gives the project its analytics beyond raw tracking. Using heuristic-based logic, it flags a "duel" whenever two opposing players and the ball all end up within a certain distance of each other. Once a duel is flagged, the outcome is decided by which team's player ends up closer to (or in possession of) the ball once the duel resolves. If it's too close to call, the duel is marked as contested instead of awarding a win.

Every duel is logged with its outcome and pitch location, which rolls up into match-level stats: total duels, wins by team, contested duels, and a possession win rate (plus a pitch map showing exactly where on the field each duel took place).
π οΈ Modes
main.py can be run in any of the following modes:
| Mode | Description |
|---|---|
PITCH_DETECTION | Annotates pitch keypoints and field edges |
PLAYER_DETECTION | Draws bounding boxes around players, goalkeepers, referees, and the ball |
BALL_DETECTION | Tracks the ball with a trailing, color-coded dot trail |
PLAYER_TRACKING | Labels each player with a persistent tracker ID |
TEAM_CLASSIFICATION | Colors players by team and marks referees separately |
RADAR | The full pipeline β team colors on the video plus the radar pitch overlay |
REFEREE_DIAGNOSTIC | Prints confidence score statistics for referee detections |
PLAYER_DIAGNOSTIC | Prints confidence score statistics for player detections |
π» Technology
- Ultralytics YOLO: Object detection and pitch keypoint detection.
- Supervision: Detection utilities, ByteTrack, video I/O, annotators, and the SAHI slicer.
- OpenCV: Frame-level drawing, homography, and video I/O.
- scikit-learn: PCA and KMeans for team clustering.
- NumPy: Array operations throughout the pipeline.
π οΈ Installation
git clone https://github.com/AggieSportsAnalytics/duel-vision.git
cd duel-vision
pip install git+https://github.com/roboflow/sports.git
cd examples/soccer
pip install -r requirements.txt
# Download model weights and sample videos
./setup.shThen run the full pipeline on a sample video:
python examples/soccer/main.py \
--source_video_path examples/soccer/data/MonUCD.mp4 \
--target_video_path examples/soccer/data/output.mp4 \
--device cpu \
--mode RADARUse --device cuda or --device mps for GPU acceleration.
π€ Contributing
- Project Managers: Samaya Sankuratri, Viet-Thy Tran
- Project Members: Edan Cho, Oscar Pineda, Sunetra Maddipatla, Ayaan Puri
π― Areas of Improvement
- Real-time processing: Move from post-processing a recorded video to analyzing a live feed.
- Automatic camera calibration: Handle new camera angles and pitch types without re-annotating keypoints.
- Player identification: Extend tracking to recognize specific players (e.g. by jersey number) rather than anonymous tracker IDs.
- Match analytics: Layer in derived stats β possession, formation shape, distance covered β on top of the tracked positions.