Football Analysis using YOLO

The goal of this project is to detect and track players, referees, and footballs in a video using YOLO, one of the best AI object detection models available. We will also train the model to improve its performance. Additionally, we will assign players to teams based on the colors of their t-shirts using Kmeans for pixel segmentation and clustering. With this information, we can measure a team’s ball acquisition percentage in a match. We will also use optical flow to measure camera movement between frames, enabling us to accurately measure a player’s movement. Furthermore, we will implement perspective transformation to represent the scene’s depth and perspective, allowing us to measure a player’s movement in meters rather than pixels. Finally, we will calculate a player’s speed and the distance covered. This project will be useful for football coaches, analysts, and fans who want to analyze a player’s performance in a match.
Features
- Player Detection: Detects players in the video using YOLO Models.
- Foot Ball Detection: Detects Football in the video continuously.
- Ball COntrol: Measures the ball control of the players.
- Speed Measurement: Measures the speed of the players.
- Distance Measurement: Measures the distance covered by the players.
Frameworks and Libraries
- YOLO - YOLO is a state-of-the-art, real-time object detection system. It is a deep learning algorithm that can detect objects in real-time. YOLO is a clever neural network for doing object detection in real-time. YOLO stands for ‘You Only Look Once’.
- PyTorch - PyTorch is an open source machine learning library based on the Torch library. It is used for applications such as natural language processing. It is primarily developed by Facebook’s AI Research lab.
- OpenCV - OpenCV is a library of programming functions mainly aimed at real-time computer vision. Originally developed by Intel, it was later supported by Willow Garage then Itseez. The library is cross-platform and free for use under the open-source BSD license.
- CNNs - In deep learning, a convolutional neural network (CNN, or ConvNet) is a class of deep neural networks, most commonly applied to analyzing visual imagery.
- KMeans - K-means clustering is a method of vector quantization, originally from signal processing, that aims to partition n observations into k clusters in which each observation belongs to the cluster with the nearest mean.
- Optical Flow - Optical flow or optic flow is the pattern of apparent motion of objects, surfaces, and edges in a visual scene caused by the relative motion between an observer and a scene.
- Perspective Transformation - Perspective transformation is a way to represent 3D objects in a 2D plane. It is used to represent the depth and perspective of a scene.
Models Used
- YOLO: AI object detection model
- Kmeans: Pixel segmentation and clustering to detect t-shirt color
- Optical Flow: Measure camera movement
- Perspective Transformation: Represent scene depth and perspective
- Speed and distance calculation per player
- And a trained model – Trained Yolo v5
Installation & Running
- Clone the repository and navigate to the directory
git clone https://github.com/Chaganti-Reddy/Football-Analysis-YOLO.git && cd Football-Analysis-YOLO
Change the path of video file to be analyzed in the main.py file.
Install these requirements.
- python3.8
- ultralytics
- pytroch
- pandas
- numpy
- opencv
Sample input video - Use this video to test the application.
Then run the following command to run the application.
python main.py