Duel Vision

A computer vision pipeline that tracks players, the ball, and team formations in soccer match footage.

🏁 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:

ModelWhat It Does
football-player-detection.ptDetects players, goalkeepers, and referees in each frame
football-ball-detection.ptA specialized ball-only detector that runs on sliced 640Γ—640 tiles (via SAHI) to catch the ball even at small scale
football-pitch-detection.ptA 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:

  1. 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.
  2. 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.
  3. Dimensionality reduction β€” PCA compresses each 24-dimensional histogram down to 3 components.
  4. Clustering β€” KMeans splits the projected crops into two clusters, one per team.
  5. 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.

Duel Analytics dashboard

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:

ModeDescription
PITCH_DETECTIONAnnotates pitch keypoints and field edges
PLAYER_DETECTIONDraws bounding boxes around players, goalkeepers, referees, and the ball
BALL_DETECTIONTracks the ball with a trailing, color-coded dot trail
PLAYER_TRACKINGLabels each player with a persistent tracker ID
TEAM_CLASSIFICATIONColors players by team and marks referees separately
RADARThe full pipeline β€” team colors on the video plus the radar pitch overlay
REFEREE_DIAGNOSTICPrints confidence score statistics for referee detections
PLAYER_DIAGNOSTICPrints 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.sh

Then 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 RADAR

Use --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.