Skip to content

AI-powered football analytics system using YOLO, ByteTrack, Optical Flow and Perspective Transform to detect players & ball, track movement, assign teams via jersey color, and compute ball possession, speed, and distance metrics from match footage.

Notifications You must be signed in to change notification settings

PRIYANGSHU018/AI-Powered-Football-Analytics-System

Repository files navigation

⚽ Football Player Tracking & Analytics System (YOLO + CV + AI)

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.


🎥 Demo

Input Match Footage Output With Tracking & Analytics
Raw broadcast video Real-time tracking & possession stats

Demo GIF Preview 👇

Demo GIF


🚀 Features

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

📂 Project Structure


├── 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


🧠 How It Works (Pipeline Architecture)

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]
Loading

📦 Installation

git clone https://github.com/yourname/football-tracking-analytics.git
cd football-tracking-analytics
pip install -r requirements.txt

▶️ Running the Project

python main.py

Output saved to:

output_videos/output_video.avi

🏋️ Model Training (YOLO)

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

📈 Results & Metrics

Metric Value
mAP@50 0.92
mAP@50-95 0.78
Precision 0.89
Recall 0.87

Detection Performance Visualization

Model Results


🛠 Tech Stack

  • Python, OpenCV, Numpy, Pandas
  • YOLOv8 (Ultralytics)
  • Supervision (ByteTrack)
  • Scikit-learn (KMeans)
  • Optical Flow (Farneback)
  • Perspective Transform (Homography)

🚀 Future Improvements

  • Jersey number recognition
  • Automated event detection (pass, foul, shot)
  • Predict xG & tactical heatmaps
  • Real-time live stream integration

📧 Contact

👤 Priyangshu Majumder 📍 India 💼 Email: priyangshumajumder9@gmail.com


About

AI-powered football analytics system using YOLO, ByteTrack, Optical Flow and Perspective Transform to detect players & ball, track movement, assign teams via jersey color, and compute ball possession, speed, and distance metrics from match footage.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published