How to become the next C. Ronaldo (using Computer Vision)?

Thomas Taieb
5 min readOct 16, 2019

Last year (2018), something amazing happened in Russia (for once!). In front of 1.12 billion people, France won the 2018 World Cup. If you don’t understand the importance of that event, you must be american. It’s okay. Nobody’s perfect! Maybe you’ll be more sensitive to the numbers.

The thing is, another one is coming in about 3 years (2022). I recently moved to Brazil. It is important for me to keep the bragging rights. Unfortunately, the coach has lost my phone number so I won’t be part of the team. Or will I?!

Fine, I found another way to help anyway! Why not using computer vision/augmented reality to train the next generation of players?!

Augmented reality

Yep, reality (sometimes) sucks. If you don’t believe me, ask them! Let’s augment it! Want to throw Angry Birds against your ugly furniture? Done. Want your workers to have the right, just on time information? Done. Want to train in your living room with the best football players? Done!

Before we go on, let’s be serious and define AR using big words:Augmented reality (AR) is an interactive experience of a real-world environment where the objects that reside in the real world are enhanced by computer-generated perceptual information, sometimes across multiple sensory modalities, including visual, auditory, haptic, somatosensory and olfactory”. Thank you Wikipedia!

Juggling is not just for clowns

Since the revival of It, clowns are living another ice age. The art of juggling is taking a hit. I am taking a stand. Not under my watch!!

Juggling might be one of the first exercises done in soccer training. It is very useful to develop balance, technicality, ball-touch and much more. It is tedious and somewhat frustrating at first. You can’t really improve from feedback (you should do this or that). You can only get better by practicing, alone. Perfect for an at-home setting.

The counter

It sounds like a scary action movie from the 90’s. But it simply counts the number of juggles done. In real time. Why is it interesting? For many reasons:

  • the player can laser focus on juggling,
  • you can quantify progress (last week you trained 7 times and increased your average by 10 juggles vs this week you trained only once and your average decreased by 5),
  • or you can back up your claims with facts (I surely believe you did 150 on your head, wink wink).

The truth is, I’m just experiencing with computer vision.

How is it done?

When juggling, the ball goes up and down. Up and down. Up and down. In physics, it is called an oscillation. The idea was to:

  • isolate the ball (with a color filter),
  • calculate the location of its center,
  • isolate its Y coordinate (in 2D space, Y is the indicator of “height”),
  • count the number of peaks and tadaaa.

In graph, it looks something like that (X axis express time as number of frames in the video):

Y position of ball center through time

NB: we actually take the inverse of the Y coordinate because in CV, the origin is on the top left corner (vs bottom left). Anyway…

Shadow training

Once you paid your dues and know how to juggle (and assuming you didn’t get kicked out for break everything), you can advance to step #2.

In racing video games, you often see your best lap as a shadow (in some specific mode). The idea is to give you an indication about how (well) you are doing, in real time, without having to look away. Let’s take that idea, and transfer it to our super trainer. The pro player is demonstrating a trick on video. Then it is your turn. To help you, you can see on the screen where the ball is supposed to be and check if you are doing it right.

How is it done?

Once again, it is super simple. I:

  • recorded myself (Lionel was unavailable) doing the trick,
  • processed the video to isolate the ball,
  • calculate the location of its center and store it in a variable,
  • to be used in the live feed to draw the shadow ball.

Time travelling

Edgar Davids was one of the greatest and most recognizable players of the 90’s / early 2000. My theory is that he was originally from the future and traveled through time to secretly use my “technology” to become a superstar. Let me explain. He always played with glasses on. While everybody thinks his glasses were normal, I suspect that they were augmented reality googles that indicated him what to do.

Augmented indoor soccer

I can’t exactly pinpoint when in the future (he is from) because my app is not there yet. But (obviously) it will.

Juggling and touching the ball is great, but it is useless unless you score more goals than your opponent. And for that, you need training on passing and shooting! Don’t worry, I got you covered. The app can transform any room into a soccer pitch with virtual goals or virtual teammates. And the crowd goes wild!

How is it done?

Easy is always better. So I simply (cheated and assumed the camera was steady and at the level of the player’s eyes):

  • added the image of a goal onto the live image,
  • isolated the ball (with a color filter),
  • calculated the location of its center,
  • and checked if the ball crossed the line.

NB: I badly cropped the video but you can “see” on top left of the screen the crowd screaming “GOOOOOOOOALLLLL”.

There are so many ways to make the app better. If you are a developer, a tinkerer, a crazy person or any other adjective, please feel free to reach out. We can train the next generation of professional athletes. Or just have fun at the office, for once!

NB: code available here. I highly welcome any feedback!!

--

--

Thomas Taieb

Financial analyst in M&A, love everything about technology, start-ups and business.