This project is a full-fledged Football Analysis System built using YOLOv5, OpenCV, PyTorch, and Computer Vision techniques. It demonstrates real-time object detection, player tracking, team assignment, camera motion compensation, speed and distance estimation, and perspective transformation — all aimed at analyzing football matches intelligently.
Inspired by the tutorial by Code In a Jiffy
In this project, you'll build an end-to-end sports analytics system. Specifically, you'll learn to:
- 🧠 Use Ultralytics YOLOv5 for detecting players, referees, and balls in football videos.
- 🧪 Train your own YOLO model on custom datasets for better detection accuracy.
- 🎨 Apply KMeans clustering for segmenting player t-shirt colors and assign teams.
- 🎥 Estimate camera movement using Optical Flow.
- 🧭 Implement Perspective Transformation to map video coordinates to real-world coordinates.
- 🏃 Measure each player’s distance covered and speed over time using tracking data.
FOOTBALL\_OBJECTDETECTION/
├── camera\_movement\_estimator/
├── development\_and\_analysis/
├── player\_ball\_assigner/
├── speed\_and\_distance\_estimator/
├── team\_assigner/
├── trackers/
├── training/
├── utils/
├── Videos/
├── view\_transformer/
├── main.py
├── yolo\_inference.py
├── README.md
├── pyproject.toml
└── .gitignore
⚠️ Python 3.12+ is required.
# Clone the repository
git clone https://github.com/Arcane-WD/football-object-detection.git
cd football-object-detection
# Install dependencies using uv (recommended)
uv venv
uv pip install -r requirements.txt # or use pyproject.tomlIf you're not using uv:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt- 📦 Kaggle Football Dataset (Videos were removed)
- 📼 Google Drive Video (used instead of removed Kaggle videos)
- 🎯 Roboflow Football Dataset
| Feature | Description |
|---|---|
| YOLOv5 Object Detection | Detect players, referees, and the ball in each frame |
| Custom Model Training | Train your own YOLO model using annotated data |
| Tracking | Track objects across frames using bounding boxes |
| Team Color Clustering | Assign teams using KMeans on jersey color |
| Ball Possession Detection | Assign ball possession to players |
| Camera Motion Estimation | Adjust player positions with optical flow |
| Perspective Mapping | Map pixel positions to meters |
| Speed & Distance Estimation | Calculate player distance covered and movement speed |
| Time | Feature |
|---|---|
| 00:00 | Introduction |
| 01:19 | YOLO Object Detection & Tracking |
| 01:55:30 | Team Color Assignment |
| 02:32:00 | Ball Interpolation |
| 03:06:25 | Camera Movement Estimator |
| 03:41:50 | Perspective Transformer |
| 04:05:40 | Speed & Distance Estimator |
See full video here
Outputs such as tracked videos, player labels, and speed overlays are saved in the /Outputs directory.
python main.pyEnsure your input videos are in the Videos/ folder.
This project is for educational and research purposes. Please credit the original author for the tutorial and data sources when reusing.
- Ultralytics YOLOv5
- Code In a Jiffy YouTube Tutorial
- Roboflow & Kaggle for datasets

