Live Sketching Program Using Open CV and Python

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.

Live Sketching Program Using Open CV and Python
Input (on left) from the webcam feed and the Output (on right)

NumPy is used for scientific computing with Python. It has certain features:

  1. A powerful N-dimensional array object
  2. Sophisticated (broadcasting) functions
  3. Tools for integrating C/C++ and Fortran code
  4. 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:

Live Sketching Program Using Open CV and Python
Installing OpenCV and Numpy using CMD (Command Prompt)

Now you need to open your python script. We define OpenCV and Numpy in our code as follows:

Live Sketching Program Using Open CV and Python
Defining OpenCV and Numpy

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:

Live Sketching Program Using Open CV and Python
Extracting image frames from the webcam video feed

Now we have to convert our color image to Grayscale for fast and easier processing.

Live Sketching Program Using Open CV and Python
Converting color image to Grayscale.

Now we’ll blur the image using the Gaussian Blur filter that OpenCV provides us.

Live Sketching Program Using Open CV and Python
Applying Gaussian Blur filter

Here comes the most important part! DETECTING EDGES!

Live Sketching Program Using Open CV and Python
Edge detection

And now the last thing! Applying threshold inversion to get the final touch.

Live Sketching Program Using Open CV and Python

Live Sketching Program Using Open CV and Python
OUTPUT!

Complete Code

Live Sketching Program Using Open CV and Python
Complete Source Code!

Leave a Reply

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