Giter VIP home page Giter VIP logo

mostafa-nafie / football-object-detection Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 6.0 123.45 MB

This is a computer vision project that utilizes object detection algorithms to analyze football matches videos by finding the position of players, ball and referees on the football pitch and finding out to which team each player belongs.

Jupyter Notebook 99.92% Python 0.08%
computer-vision football football-analytics object-detection yolo yolov8 kmeans-clustering soccer soccer-analytics soccer-data

football-object-detection's Introduction

Football Object Detection

This project utilizes object detection algorithms to analyze football matches videos by finding the position of different objects on the football pitch and classifying them into 7 different classes:
0 - Player team left
1 - Player team right
2 - Goalkeeper team left
3 - Goalkeeper team right
4 - Ball
5 - Main referee
6 - Side referee
7 - Staff members

Demo

CityUTdR_out.mp4

Quick Guide

Install
git clone https://github.com/Mostafa-Nafie/Football-Object-Detection.git
cd "./Football-Object-Detection"
pip install requirements.txt
Inference on video

To run the model on a video, run the following command:

python main.py /path/to/video

The annotated video will be saved to "Football Object Detection/output" folder

Object Detection model

The model used for object detection is YOLOv8, it was trained on SoccerNet Dataset for 25 epochs, to classify the objects into only 5 different classes:
0 - Player
1 - Goalkeeper
2 - Ball
3 - Main referee
4 - Side referee
5 - Staff members

How it works ?

The model uses the first frame of the video to extract some important information by performing the following steps:
1. Extracting the grass color
It works by selecting only the green colors in the frame and masking out all other elements, then taking the average color of the non-maksed parts
image

2. Finding the kit color of each one of the two teams
This can be done by cutting the players boxes out of the image and then removing the grass from the background of each player and finally get the average color of the remaining pixels, which will be the player's kit color, then the K-Means clustering alogrithm will be used on the BGR values of the kits colors, so that each team's kits will be clustered together in one group, with its centroid representing the team's kit color for future comparisons. image

To remvoe the grass color from each player's background, I filter out the region of colors around the grass color that we got in the first step in the HSV color space. image

3. Labeling each team as left or right
To do this, I find the average position of each team's players on the x axis, and the team with the least average position value will be labeled as "Team Left" and the other one as "Team Right" image

For every frame of the video, the model operates as follows:
1. Running YOLO model inference on the current frame
The model classifies each object into one of the 5 classes
image

2. Finding the kit color of each player
By using the same method as before, removing the grass background from the player's bounding box and getting the average color of the remaining pixels.

3. Classifying each player into "team 0" or "team 1"
This is done by finding out to which closest K-Means centroid (found in the first frame) to the player's kit color. image

4. Labeling each team as "Left" or "Right"
This is done by comparing the team's label (0 or 1) to the label of the "Team Left" found in the first frame

5. Labeling each Goalkeeper The goalkeeper is labeled "GK Left" if he's found on the left hand side of the frame, and labeled "GK Right" otherwise.

Further explanation of the model can be found in the jupyter notebook.

football-object-detection's People

Contributors

mostafa-nafie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

football-object-detection's Issues

Doubt regarding dataset

Hey there, i hope you are doing okay, i just want to ask as the soccer net dataset is jumbled up, each and every events of match like yellow card , red card, goals, free kick are in different folder with regards to match, how did u put them in single folder train and test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.