Football Statistics generator with Python
This Python code provides a basic statistic/visualization generator than can be use to asses the percentage of posession for each team, the heatmap of the ball and diferent players. It expandes the roboflow player object dection. Its is not perfect and was just intended as a fun personal project.
08fd33_4.webm
It uses a YOLOV8
model to detect players in every frame, a tracking Bytrack
model to asign a id to every player and a KNearestNeighbour
algorithm to cluster the players in two teams based on the HSV of the object detection bounding box.
08fd33_0.webm
It uses the previous YOLOV8
model to predict the ball and a new model to predict the keypoints of the football field needed to compute the homography matrix.
08fd33_0_warped.webm
It uses the homography matrix to compute the bird view of the football field and the ball trajectory using some open-cv
modules.
An overview of the code structure can be found here
- Clone ByteTrack
- Clone Yolov5
- Install project with :
pip install -e .
python launch.py hsv-team-posession-tracking
or
python launch.py ball-homography