This project detects and tracks football players, referees, and the ball from broadcast match footage using YOLO Object Detection and advanced Computer Vision techniques.
It assigns players to teams using KMeans color clustering, calculates ball possession percentage, estimates speed & distance covered, and stabilizes tracking even under camera movement using optical flow compensation.
| Input Match Footage | Output With Tracking & Analytics |
|---|---|
| Raw broadcast video | Real-time tracking & possession stats |
Demo GIF Preview 👇
| Module | Description |
|---|---|
| YOLOv8 Object Detection | Detects players, referees, and ball |
| ByteTrack Tracking | Stable multi-object ID tracking |
| KMeans Clustering | Team assignment based on jersey color |
| Ball Possession Analytics | Calculates team ball control percentage |
| Optical Flow Camera Stabilization | Compensates for panning camera |
| Perspective Transformation | Field view correction to measure in meters |
| Speed & Distance Estimation | Compute movement metrics per player |
├── assets/
│ └── demo.gif
├── input_videos/
│ └── 08fd33_4.mp4
├── output_videos/
│ └── output_video.avi
├── models/
│ ├── best.pt
│ └── last.pt
├── stubs/
│ ├── track_stubs.pkl
│ └── camera_movement_stub.pkl
│
├── trackers/
│ └── tracker.py
├── team_assigner/
│ └── team_assigner.py
├── player_ball_assigner/
│ └── player_ball_assigner.py
├── camera_movement_estimator/
│ └── camera_movement_estimator.py
├── view_transformer/
│ └── view_transformer.py
├── speed_and_distance_estimator/
│ └── speed_and_distance_estimator.py
│
├── utils/
│ ├── bbox_utils.py
│ └── video_utils.py
│
├── training/
│ └── football_training_yolo_v5.ipynb
│
├── metrics/
│ └── results.png
├── requirements.txt
├── main.py
└── README.md
flowchart LR
A[Input Video] --> B[YOLO Detection]
B --> C[ByteTrack Tracking]
C --> D[Camera Movement Estimation]
D --> E[Perspective Transform]
E --> F[Speed & Distance Calculation]
C --> G[KMeans Team Assignment]
C --> H[Ball Assignment]
H --> I[Ball Possession %]
F --> J[Annotated Output Video]
git clone https://github.com/yourname/football-tracking-analytics.git
cd football-tracking-analytics
pip install -r requirements.txtpython main.pyOutput saved to:
output_videos/output_video.avi
Dataset structure used for training YOLO:
datasets/
├── images/train
├── images/val
├── labels/train
└── labels/val
Example command:
yolo train model=yolov8x.pt data=football-dataset.yaml imgsz=640 epochs=100 batch=16| Metric | Value |
|---|---|
| mAP@50 | 0.92 |
| mAP@50-95 | 0.78 |
| Precision | 0.89 |
| Recall | 0.87 |
- Python, OpenCV, Numpy, Pandas
- YOLOv8 (Ultralytics)
- Supervision (ByteTrack)
- Scikit-learn (KMeans)
- Optical Flow (Farneback)
- Perspective Transform (Homography)
- Jersey number recognition
- Automated event detection (pass, foul, shot)
- Predict xG & tactical heatmaps
- Real-time live stream integration
👤 Priyangshu Majumder 📍 India 💼 Email: priyangshumajumder9@gmail.com

