In this Repo, we have provided the tracking of football players using Background Subtraction and classifying them using a neural network.
For detecting players we have used Background Subtraction Methods such as MOG2, KNN, etc.
Because every area, of the frame, has different features, such as upper area has a lot of noise and players are smaller than lower areas, ..., We have split the frame into 3 section:
-
Upper Area: which we do Erosion first for removing the Banners and anything the above them.
-
Middel Area: we do Erosion first for removing the ball and any other noises. Then we do Dilation for making players bigger.
-
Lower Area: Because in the lower area players are much bigger than two other areas, we do Closing.
all you can see in get_blobs
function in main.py
file. feel free to change the kernels and see what will happend.
For classifying players of the teams and referees, we have used Neural Network. Our framework for building the Neural Network was Tensorflow(Keras).
Our dataset was from https://datasets.simula.no/alfheim/ that provides us with three points of view from the football field.
We have four different trained models(that you can see in model_4, model_5, model_6, model_7
folders), each has an accuracy of around 97%, the best of them is model_4
with the validation accuracy of 98% that use the lenet 5 architecture. If you want to change the architecture and see the result, you can change the build_model
function in model_architecture.py
file.
python3 -m venv env # or you can use virtual env but python3 is requred
source ./env/bin/activate
pip install -r requirements.txt
python main.py