Start your Computer Vision journey here with OpenCV and Python
Computer Vision is more relevant than ever. Just think about all the real-time processing of live video streams. From the simple things like reading the license plate of cars driving into a parking lot, to the more complex of analyzing the mood people express.
There is so much potential things to use Computer Vision for in live video streams.
This guide will get you a basis of Computer Vision using OpenCV and Python.
I know what you are thinking. Computer Vision requires a lot of fast processing, which cannot be efficient with Python.
Let’s start this journey together. If you are already hooked on this, then I would advice you to take my online course, which explains the theory in more details.
Step 1: What is Computer Vision and OpenCV?
Take a look at the following image.
You will immediately see a woman, possibly a mother, reading a book for a child, which is most likely her child.
Now imagine you need to program a computer to get that understanding from a picture.
That is difficult.
OpenCV is aimed at real-time computer vision and has a great integration with Python. Real-time computer vision, simply means to gain high level understanding of what is happening in a live video stream. It could be from a movie, surveillance camera, your webcam, or whatever live feed you have.
This guide will get you in the game of real-time computer vision, from installing the library to make awesome applications counting cars, noise tolerant motion detection and more.
Step 2: Installing OpenCV in PyCharm
If you are serious about Python you need to use PyCharm for your application development. Go get your free community version of PyCharm here, and you will never regret it in your life.
Now the next step is to install the OpenCV library in your PyCharm environment. This tutorial will guide you through this process.
Step 3: Start simple – insert a logo in a live steam
The first step is to understand the basic processing cycle. A video is a sequence of images, when you process a video, you are actually processing a sequence of images.
Hence, a process inserting a logo into a live stream, will insert a logo on a sequence of images.
Also, this tutorial will introduce the data structure used to represent images.
Step 4: Counting cars – a simple approach
Wow. Big step.
This might surprise you. But with a simple approach you can actually count cars in a live video stream.
Think about it, if you have a static camera pointing at a road, it is pretty obvious that if an object moves though one part of the stream it is a car driving in one direction. While in another part of the stream, it will be a car driving in the other direction.
This is not a fully accurate way to count cars, but in many cases it will do pretty good.
Step 5: Noise tolerant motion detector
We already did a motion detector in the previous step. It will do quite good, but it can be challenging if the background is noisy.
To deal with that you introduce a noise tolerant motion detector.
Step 6: Motion tracker
A fun thing to do is to create a motion tracker. What? Something that can track objects in your live video stream.
That sounds more complex than it is, and it is more fun than you can imagine.
Understand how it works and implement it with your webcam.
Step 7: How to track and replace the object
This is even more fun than the previous one. How can you track, say, something blue and replace that with another object you insert.
Here we combine things. We combine tracking and inserting things, as we learned in previous steps.
This is one of my favorite and it was a lot of fun to make.
Step 8: Blur the background
In times of many online meetings, where we sit at home, we often want to hide the background. You see this option in many, if not all, online meetings solutions.
The motivation is quite understandable, you don’t want others to see that you did not clean your apartment for the last 9 months. You want your privacy.
In this tutorial we take a simple approach how to make that.
Step 9: Create a cartoon background
Now we are working on extracting foreground and background you can do a tons of fun things.
In this one we try to change the background to be like a cartoon. So you will be moving human in a cartoon.
That is just so funny.
Step 10: Reverse that – you are the cartoon in the real world
Why not reverse that?
You become the cartoon moving around in the real world.
This is what makes real-time computer vision funny. When you extract foreground from the background there are endless options to play with.
Step 11: Make a funny game
This tutorial went almost viral! Or maybe it did… Honestly, I do not know what it takes. People loved it.
…it is both silly and extremely funny to make. I had a blast making it.
The game is simple. Avoid falling objects from the sky.
Step 12: Move objects around in the live web-stream
Now we are getting somewhere. We will start interacting with objects that we inserted in the live web stream.
This is amazing. We interact with the computer world.
Step 13: Time to understand things a bit deeper – color to gray scale
As a Computer Vision expert you need to understand some basics of how it works.
First, how does it work to gray scale?
Step 14: Learn about Numba – for fast processing in Python
Sometimes the library does not have your desired functionality. Then luckily someone has created Numba, which can make it efficient for you.
This tutorial will introduce it to you with a good example.
Step 15: Mosaic on live video stream
Another fun thing to play with is mosaic.
A good question can that be optimized to do on a live video?
Check out the solution here in this tutorial, where we combine it with Numba to get the required speed.
Step 16: Mosaic with faces
That is a common to create mosaic of a face using small images of faces.
Now we know how to make efficient mosaic, let’s try to make it a bit more elegant with real data. This tutorial will help you collect images of faces (without copy right issues).
This is a tutorial that takes a bit more time to run, as it will need a lot of images.
Step 17: ASCII art mosaic in a live video stream
I am an old computer geek growing up with ASCII and only ASCII. We tend to love the old days and old technology.
ASCII art is one of those things that still live among us. Why not try to make it work on a live video stream.
Are you done? No, this is getting you started to this amazing world of possibilities.
I love to play around with things creating simpler approaches, which are not always perfect, but helps you understand the concepts easier.
A great way to improve your skills is to go a bit deeper into the theory by joining my online course on the subject.
I will be happy to hear from you. Feel free to reach out to me on a social media channel.