Machine Learning

AI Meets ‘The Beautiful Game’

The article explores the science behind the controversial topic of VAR in soccer and looks to explain it with a simple example using OpenCV.

Football is the world’s most popular sport. ‘The Beautiful Game’ has an estimate of between three and four billion fans worldwide. While these fans spend hours debating topics such as ‘is Messi or Ronaldo the GOAT?’, ‘is Mbappé or Haaland the greatest up and coming youngster?’ and ‘which EPL side will crack the top four this year?’, there has been one relatively new topic of conversation that has emerged and has been the center of much debate over recent time – VAR.

VAR is defined as “an assistant referee in association football who reviews decisions made by the head referee with the use of video footage and headset for communication specifically in order to minimize human errors causing substantial influence on match results” – Wikipedia

VAR systems are being increasingly adopted by football leagues around the world. Since 2018, the VAR system application is written into the laws of the game in a bid to increase integrity and fairness. VAR is used to assist the referee in his or her decision-making. It is restricted to the review of four categories of match-changing incidents:

  • Goals
  • Penalties
  • Direct red cards
  • Mistaken identity

AI and VAR

One of the most significant advancements has been the use of Artificial Intelligence (AI) to facilitate the identification of offside offenses. This latest generation of VAR is based on a neural network technique that automatically calibrates the field of play to position a clear 3D offside line overlay graphic – a massive step towards easier, faster, and more precise live video assistance. This automatic calibration is based on real-time analysis of the images generated by the broadcast cameras surrounding the field.

For each video image, the AI engine calculates the transformation between the camera image and the 2D layout of the field – allowing to easily draw the line to the real image or with the right perspective. The integration of image recognition in the system eliminates the need for a time-consuming manual pregame setup. Now with AI, the virtual offside line is generated in less than one second. And because the system will continually recalibrate itself from the images generated from the broadcast cameras, theoretically, officials can trust that everything is calculated with the highest level of precision.

Simple Object Detection and Labelling Exercise

I wish to demonstrate how a neural network can be used to accurately identify the location of a football player on the football pitch, to be used to assist VAR in determining whether that player is in an offside position.

Below is an object detection program in Python using very few lines of code.

The algorithm uses OpenCV which is an open-source, cross-platform library of programming functions aimed at real-time computer vision. I recommend that you read a recent article written by a close colleague of mine for a more detailed description of the computer vision algorithm.

The code I used is as follows:

import cv2
import matplotlib.pyplot as plt
from cvlib.object_detection import draw_bbox

input_image = cv2.imread('football_player.jpg')
bounding_box, label, confidence = cv.detect_common_objects(input_image)
output_image = draw_bbox(input_image, bounding_box, label, confidence)

Using the code above, we are able to load in an image of footballers on a football field, such as the image below.

We can then use OpenCV’s detect_common_objects function to fit bounding boxes around the detected images, and display the classification (or label) of those images and the confidence that the algorithm has in this detection.

We can use the above to plot the original image along with the bounding boxes and labels of each football player and display this (as seen in the image below).

Identification and classification of football players from the algorithm


This simple object detection algorithm has allowed us to identify and classify football players on a football field. This can be used to accurately determine the location of the players on the pitch and ascertain whether that player is in an offside position. I hope that you now have better understanding of how VAR works and that this article has perhaps shifted your perspective on this controversial football topic.

Enjoyed this read?

Stay up to date with the latest AI news, strategies, and insights sent straight to your inbox!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.