In this video, you’ll learn how to use machine learning, computer vision and deep learning to create a football analysis system. This project utilizes YOlO a state of the art object detector to detect the players, referees and footballs. It also utilizes trackers to track those object across frames. We also train our own object detector to enhance the output of the state-of-the-art models. Additionally, we will assign players to teams based on the colors of their t-shirts using Kmeans for pixel segmentation and clustering. 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 covers various concepts and addresses real-world problems, making it suitable for both beginners and experienced machine learning engineers.

In this video you will learn how to:
1. Use ultralytics and YOLOv8 to detect objects in images and videos.
2. Fine tune and train your own YOLO on your own custom dataset.
3. Use KMeans to cluster pixles and segment players from the background to get the t-shirt color accurately.
4. Use optical flow to measure the camera movement.
5. Use CV2’s (opencv) perspective transformation to represent the scene’s depth and perspective.
6. Measure player’s speed and distance covered in the image.

Datasets:
kaggle Dataset:
Video link used because Kaggle removed the videos from the kaggle dataset above:
Robowflow Football Dataset:

Github Link:

๐Ÿ”‘ TIMESTAMPS
================================
0:00 – Introduction
1:19 – Object detection (YOLO) and tracking
1:55:30 – Player color assignment
2:32:00 – Ball interpolation
3:06:25 – Camera movement estimator
3:41:50 – Perspective Transformer
4:05:40 – Speed and distance Estimator

source

div style="text-align: center;">
37 thoughts on “Build an AI/ML Football Analysis system with YOLO, OpenCV, and Python”
  1. One problem which I am facing is my players tracking id gets changed when they enter from one frame to another can anyone help me with this , I am using the same code for my clip

  2. hello sir. hope you're doing well. i got an error that i tried to solve but since i don't find any solution. may you please help me? here is the error: PS C:Userschrisfootball_analysis> & c:/Users/chris/football_analysis/env/Scripts/python.exe c:/Users/chris/football_analysis/main.py

    Traceback (most recent call last):

    File "c:Userschrisfootball_analysismain.py", line 87, in <module>

    main()

    ~~~~^^

    File "c:Userschrisfootball_analysismain.py", line 26, in main

    camera_movement_estimator = CameraMovementEstimator(video_frames[0])

    ~~~~~~~~~~~~^^^

    IndexError: list index out of range

    PS C:Userschrisfootball_analysis> & c:/Users/chris/football_analysis/env/Scripts/python.exe c:/Users/chris/football_analysis/main.py

    Traceback (most recent call last):

    File "c:Userschrisfootball_analysismain.py", line 87, in <module>

    main()

    ~~~~^^

    File "c:Userschrisfootball_analysismain.py", line 26, in main

    camera_movement_estimator = CameraMovementEstimator(video_frames[2])

    ~~~~~~~~~~~~^^^

    IndexError: list index out of range

    PS C:Userschrisfootball_analysis>

  3. Hello Abdullah, and thank you for the very detailed video; it really inspired me to try it. I want to ask you one thing: now I am at the training phase. I see that your training in Google Colab ended in 10 epochs and in, like, 6 minutes. For me it takes much, much longer; Colab kicks me out in 3 hours, so I started the training on my MacBook Pro M4. It has now been 30 hours and is in epoch 80. Will it be ok if I end the training manually, or should I wait for the system to finish it? Or should I have changed the early stopping parameters? Thank you.

  4. I need help cause I do this as my grad project please if you can help just reply or give me an email I will send everything I need to know cause the due date is 15 days far

  5. Hello , how can I integrate this system such that the user can input any video they want and click analyze to get the analysis of their video as an annotated final output generated in this project?

  6. i got the following error in main.py

    tracker = Tracker('models/best.pt')

    TypeError: Tracker() takes no arguments/

    also in the output_videos folder the output video is not getting saved also i am unable to see the cropped image in that output_videos folder

    can someone help me solve this ?

  7. while training it didnot train epoch , training stop on vs code and colab not respond and training file generate but weight file doesnot show that 2 files weight file empty
    Starting training for 10 epochs…

    Closing dataloader mosaic

    albumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01, num_output_channels=3, method='weighted_average'), CLAHE(p=0.01, clip_limit=(1.0, 4.0), tile_grid_size=(8, 8))

    Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size

    0% 0/39 [00:08<?, ?it/s]

  8. Hi, after getting your model trained and now have your tactical map with keypoints and objects detected, how do you then capture event data from this map?
    i.e pass, shot, goal, distance covered etcโ€ฆ

  9. This tutorial was an absolute masterpiece! ๐ŸŽจโšฝ Your clear explanations and in-depth analysis made the soccer analysis project so much easier to understand. I truly appreciate the effort and expertise you put into thisโ€”thank you for sharing your knowledge! ๐Ÿ™Œ๐Ÿ”ฅ

Leave a Reply

Your email address will not be published. Required fields are marked *