This project generates automatic football match text commentary using Computer Vision and Deep Learning.
The system detects players and football from a video, tracks their movement, analyzes ball possession, and generates real-time commentary similar to a sports commentator.
The project uses YOLOv8 for object detection, tracking algorithms, and rule-based commentary generation.
- Detect players and football in match video
- Fine-tuned YOLOv8 model for accurate football detection
- Pretrained YOLO model for player detection
- Object tracking of players and ball
- Ball possession detection
- Automatic sports commentary generation
- Display processed video with commentary
- Web interface using Flask
The system follows these steps:
A football match video is provided as input.
- YOLOv8 pretrained model detects:
- Players
- Fine-tuned YOLOv8 model detects:
- Football
Players and ball are tracked across frames.
Distance between player and ball is calculated.
The closest player is considered the ball owner.
Based on ball movement and player possession.
Example commentary:
Player 3 passes the ball to Player 7
Player 5 gains possession of the ball
Player 2 intercepts the pass
Processed video and live commentary are displayed on a webpage.
sports-commentary-ai
│
├── app.py # Flask web application
├── detector.py # YOLO detection logic
├── tracker.py # Object tracking
├── possession.py # Ball possession detection
├── commentary.py # Commentary generation logic
│
├── templates
│ └── index.html # Web interface
│
├── input.mp4 # Input football video
├── output.mp4 # Processed output video
│
├── runs # Training results (YOLO)
├── models
│ └── football.pt # Fine-tuned football detection model
│
└── README.md
- Python
- OpenCV
- PyTorch
- Ultralytics YOLOv8
- Flask
- HTML / CSS / JavaScript
Install dependencies:
pip install -r requirements.txtOr install manually:
pip install ultralytics opencv-python flask torchRun the Flask server:
python app.pyOpen your browser and go to:
http://127.0.0.1:5000
The webpage will display:
- Processed football video
- Generated sports commentary
The football detection model was fine-tuned using a custom dataset.
Training command:
yolo detect train \
model=yolov8n.pt \
data=data.yaml \
epochs=50 \
imgsz=640This improves detection accuracy for small football objects.
Player 4 gains possession of the ball.
Player 4 passes the ball to Player 8.
Player 8 moves forward with the ball.
Player 10 intercepts the pass.
- Real player identification
- Team detection
- Goal detection
- Advanced NLP-based commentary
- Audio commentary generation
- Live match streaming support
Love Kumar
B.Tech Computer Science
Lovely Professional University