Harbola DataScience

Answer, Read and Post Coding related Questions!

Live Sketch using Web cam Computer Vision

Sometimes you want to draw your face but you can’t sketch. This project will help. You can take a image of your sketch and print it out and color on it.

There are many other applications too. But will keep it simple. From just opening you web cam using python to drawing lines to edges, we will cover all from basics.

This project is a computer vision task in which we will be gonna using opencv library to perform image processing.

Demo of Live sketch using web cam

In Most of the opencv project we use same functions and follow same steps. Opening webcam, reading frame, converting image to black and white or RGB. Blurring image and showing the output and destroying all windows at the end.

Let us see how we do all this in python.

First of all you need to have python installed. If not, download it from python’s official website.

Using pip in your terminal (on linux) or command prompt (on windows) install cv2 using pip install opencv-python command.

You can use any text editor (pycharm, vs code, sublime, atom…) for writing code.

Implementation of sketch using python computer vision

Import required libraries.

Here only opencv library is required to do some image processing task. If you take this to next level integrating this with some other projects. You can do that as well.

read this article to solve error you face in opencv project

Creating a function to sketch image – important

The most important part of this project is to create a function in which will pass image and it will generate a sketech of that image.

Using def we are creating our sketch named function. Next step is to convert BGR image which is default when we read image To black and white(gray scale) image. Then we will blur the image using Gaussian blur function.

We can use Canny() method of cv2 library to detect edges in an image.

Thresholding. In thresholding, each pixel value is compared with the threshold value. If the pixel value is smaller than the threshold, it is set to 0, otherwise, it is set to a maximum value (generally 255).

Passing web cam image to sketch function

The computer will read code from here. First capture web cam image, then loop read every frame of video and showing the sketch as frame is passed in sketch function. Then at last destroying the web cam window.

That’s it.

Only this much coding is required to create a live sketch using python. All the hard work is done the developers of opencv and consistently adding many features and functions to it.

Hope you will try this on your system and comment or suggestion of yours would be appriciated and incorporated from next blog post. If you face any difficulty or any resource required, feel free to dm me.

Chitranshu Harbola

Self taught programmer, Web Developer and an aspiring Machine learning engineer cum Data Science student

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top