27.4 C
HomepythonConvert Images Into Pencil Sketch Using Python

Convert Images Into Pencil Sketch Using Python

In this python project, we will convert an image into a sketch file or add a sketch filter using python OpenCV.  This project will be fun, why? Because we will create this python program in just 5 lines.

Convert Images Into Pencil Sketch Using Python
So we will use a filter in python in just 4 simple steps.First, we have to add a grey filter to our image. Then we have to invert the filter to the grey image we have created. and then we have to add a blur effect to our inverted image. And after we create a sketch image.

so let’s get started now open your favorite code editor. And create a python file. After first import the OpenCV library like import cv2. And create an Image variable to store our image. After creating a grey_img variable for the add grey filter to our image. After adding a grey filter we have to invert our image. So create another variable invert. Then invert the image After adding a blur filter. So we create another variable blur. After adding a blur effect. Invert this blur effect.
so again create a variable inverted_blur. And last we have to add a filter which is a sketch. so create a sketch variable and call cv2.divide(grey_img,inverted_blur,scale=256.0)
Now we have to save our sketch image 

Note: make sure your file extension name is png otherwise it will not work.

syntax like:sketch.png

import cv2

watch the Python Projects – Convert Images Into Pencil Sketch Using Python (5 lines)



  1. I do not know if it’s just me or if perhaps everyone else experiencing
    issues with your site. It appears as if some of the text in your content are running off the screen. Can somebody else please provide feedback and let
    me know if this is happening to them too? This might
    be a issue with my web browser because I’ve had this happen before.
    Many thanks


Please enter your comment!
Please enter your name here

- Advertisment -spot_img

Subscribe to our newsletter

To be updated with all the latest news, offers and special announcements.

Most Popular