The idea was to detect players from football video and convert it to top-down video of their coordinates on the field.
It is best explained with a result, so here are some screenshots:
The process was divided into multiple parts.
First part was to detect players on the screen and this was done using Yolov5
computer vision model.
Secondly we needed to find where are the out lines on the
screen. Here OpenCV was very useful tool. I will not go into details, but we used
Canny edge detection for detectiong edges, Hough lines for finding straight lines
and finally using some maths, calculating which lines are most probably out lines.
Third part was to calculate their positions on new screen.
Before you can run the code you need to have Yolov5 installed on your computer, together with python and pytorch. If you wish to run yolo on GPU I recommend you install CUDA first. CUDA is parallel computing platform and programming model designed exclusively for Nvidia GPU-s. With CUDA, developers are able to dramatically speed up computing applications by harnessing the power of GPUs.
YOLO stands for You Only Look Once. It's a computer vision architecture designed to be fast and to be able to detect and classify objects. For our purpose it can detect people (players) on screen and do it very well.
- Install CUDA if you have Nvidia GPU. I have cuda 11.6 installed on my computer you can install it here It takes long to download, so be patient!
- Install Python 3.9.13. Preferably using conda.
- Make sure Python is on your path so you can use it later. To check, run
pythonin your console and make sure the version and installation went fine. To add it to path, follow this tutorial. - Install Torch. I have 1.13.1. IMPORTANT! If you installed cuda, you should install it with cuda options enabled here
- Open terminal on your computer and go to the folder where you wish to install Yolov5 repository
- Run
git clone https://github.com/ultralytics/yolov5.git(from this repo) - Open cloned folder in terminal (using
cd yolov5) - Run
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI - Run
pip install -r requirements.txt
Very simply you now have Yolov5 installed!
Alternatively you can follow this tutorial. This guy explained it all very well.
In folder tests open file main. Set the variable yolov5_path to the path
where you installed your yolov5 on computer. Then you can run the file with your
preffered python editor or run it with command line.
If you have any questions, ask!

