A comprehensive computer vision system for analyzing football matches using advanced object detection and tracking techniques. This project leverages YOLO (You Only Look Once) for object detection and ByteTrack for multi-object tracking to identify and track players, referees, and the ball throughout video footage.
- Real-time Object Detection: Detects players, goalkeepers, referees, and the ball using YOLO11
- Multi-Object Tracking: Maintains consistent player identities across frames using ByteTrack
- Visual Annotations:
- Players: Red ellipses with unique ID numbers
- Referees: Yellow ellipses
- Ball: Green triangular markers
- Batch Processing: Efficient frame processing with configurable batch sizes
- Caching System: Save and load detection results to speed up subsequent analyses
- Video Output: Generate annotated video files with tracking overlays
Example of the system tracking players, referees, and ball in real-time
ultralytics
opencv-python
supervision
numpy
pickle-mixin
-
Clone the repository
https://github.com/AmmarMohamed0/Football-Analysis-System.git cd Football-Analysis-System
-
Create a virtual environment (recommended)
python -m venv football_env source football_env\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Download YOLO model
# The system will automatically download yolo11l.pt on first run
- Place your video file in the
input_videos/
directory - Run the analysis:
python main.py
- Find the output in the
output_videos/
directory
- Video Input: Load video frames using OpenCV
- Object Detection: YOLO model detects players, referees, goalkeepers, and ball
- Class Mapping: Goalkeepers are mapped to player class for unified tracking
- Multi-Object Tracking: ByteTrack maintains object identities across frames
- Visualization: Draw ellipses for people, triangles for ball with unique IDs
- Output Generation: Create annotated video with tracking overlays
To train your own YOLO model for football analysis using the Roboflow dataset:
Set up your training environment in Google Colab (Football_Analysis_System.ipynb
):
# Install required packages
!pip install ultralytics --quiet
!pip install roboflow --quiet
import ultralytics
ultralytics.checks()
from ultralytics import YOLO
from roboflow import Roboflow
Access the football players detection dataset from Roboflow:
# Initialize Roboflow with your API key
rf = Roboflow(api_key="YOUR_API_KEY_HERE")
project = rf.workspace("roboflow-jvuqo").project("football-players-detection-3zvbc")
version = project.version(1)
dataset = version.download("yolov11")
Dataset Source: Football Players Detection Dataset by Roboflow
Train the YOLO model with the downloaded dataset:
# Train the model using command line interface
!yolo task=detect mode=train data={dataset.location}/data.yaml model="yolo11l.pt" epochs=100 imgsz=640
Training Parameters:
- Model: YOLOv11 Large (
yolo11l.pt
) - Epochs: 100
- Image Size: 640x640
- Task: Object Detection
After training completes:
- Locate your trained model (usually in
runs/detect/train/weights/best.pt
) - Replace the existing
models/best.pt
with your newly trained model - Update any model paths in your configuration if necessary
The dataset includes annotations for:
- Players
- Referees
- Goalkeepers
- Ball detection
Note: Make sure to replace "YOUR_API_KEY_HERE"
with your actual Roboflow API key before running the training script.
- Detection Accuracy: Depends on custom model training
- Tracking Consistency: ByteTrack maintains 95%+ identity consistency
- Processing Speed: ~30 FPS on RTX 3080 (batch processing)
- Memory Usage: ~4GB VRAM for 1080p video processing
- YOLO: Ultralytics for object detection
- ByteTrack: Multi-object tracking algorithm
- Supervision: Computer vision utilities
- OpenCV: Image processing capabilities
⭐ Star this repository if you found it helpful!