This project implements an end-to-end football video analytics pipeline using YOLOv8, enabling player and ball detection, multi-object tracking, team assignment, and ball possession analysis, with annotated video output.
🧠 YOLOv8-based object detection (players, ball)
🎯 Multi-object tracking across video frames
🎨 Automatic team assignment based on jersey color
⚽ Ball-to-player assignment (ball possession detection)
📊 Team ball control analysis over time
🎥 Annotated output video with bounding boxes, team colors, and possession indicators
Football_ObjectDetection_Tracking_Project/
│
├── main.py # Main pipeline entry point
├── yolo_inference.py # YOLOv8 inference script
├── requirements.txt # Project dependencies
├── yolov8x.pt # Pretrained YOLOv8 model
│
├── input_videos/
│ └── input_videos.mp4 # Input football match video
│
├── output_videos/
│ └── output_video.avi # Final annotated output video
│
├── models/
│ └── best.pt # Custom-trained YOLOv8 model
│
├── stubs/
│ └── track_stubs.pkl # Cached tracking results
│
├── runs/
│ └── detect/
│ └── predict/ # YOLO detection outputs
│
├── trackers/
│ └── tracker.py # Detection & tracking logic
│
├── team_assigner/
│ └── team_assigner.py # Team color detection & assignment
│
├── player_ball_assigner/
│ └── player_ball_assigner.py # Ball possession logic
│
├── utils/
│ └── video_utils.py # Video read/write utilities
│
├── training/
│ ├── train.py # Model training script
│ └── data.yaml # Dataset configuration
│
├── development_and_analysis/
│ └── notebooks.ipynb # Experiments & analysis notebooks
│
├── __pycache__/ # Python cache files
│
├── .gitignore
├── .gitattributes
└── README.md
The system processes a football video through the following steps:
Video Loading
Reads input video and extracts frames.
Object Detection & Tracking
Uses YOLOv8 to detect players and the ball.
Tracks objects across frames.
Supports cached tracking using stub files to speed up experiments.
Ball Trajectory Interpolation
Smooths missing ball detections for consistent tracking.
Team Assignment
Learns team colors from the first frame.
Assigns each player to a team dynamically.
Ball Possession Detection
Assigns the ball to the closest player per frame.
Determines which team controls the ball over time.
Visualization & Annotation
Draws bounding boxes, team colors, and possession indicators.
Saves an annotated output video.
pip install ultralytics opencv-python numpy
Make sure you have Python 3.8+
Place your input video in:
input_videos/input_videos.mp4
Place your trained YOLOv8 model in:
models/best.pt
python main.py
Annotated video will be saved to:
output_videos/output_video.avi
The output video includes:
Player and ball bounding boxes
Team-specific colors
Ball possession indicators
Team-level ball control timeline
Python
YOLOv8 (Ultralytics)
OpenCV
NumPy
Multi-Object Tracking
Computer Vision for Sports Analytics
#🔮 Future Improvements
Player re-identification across camera cuts
Tactical heatmaps and formation analysis
Real-time inference optimization
Event detection (passes, shots, goals)