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.
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.