Let’s build a program using OpenCV to realize how powerful it is. We will develop an application that will show a live sketch of your webcam feed. In this mini-project, we’ll be using Python, NumPy, and OpenCV.
NumPy is used for scientific computing with Python. It has certain features:
- A powerful N-dimensional array object
- Sophisticated (broadcasting) functions
- Tools for integrating C/C++ and Fortran code
- Useful linear algebra, Fourier transform, and random number capabilities Besides its obvious scientific uses.
OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. It has over 2500 optimized algorithms which include a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms.
Let us get started
To get started, we need to install OpenCV and Numpy using CMD or Comand Prompt (I am assuming that you have Python installed). Steps to be followed:
Now you need to open your python script. We define OpenCV and Numpy in our code as follows:
Now the next thing we have to do is to read the frame from the webcam!
As we want to build a live application, we’ll use our webcam and extract out the image frames from the video feed. We’ll do it as follows:
Now we have to convert our color image to Grayscale for fast and easier processing.
Now we’ll blur the image using the Gaussian Blur filter that OpenCV provides us.
Here comes the most important part! DETECTING EDGES!
And now the last thing! Applying threshold inversion to get the final touch.