Converting image into sketch using python

 Here in this post, we presented a very easy python code to convert any image into sketch.

sketch in python  cv2.pencil sketch  image to cartoon python  photo sketching using opencv python  convert image to line art python  image to sketch github  pencil-sketch github

First of all you need to install OpenCv Library:

pip install  opencv-python

Python Code:

from cv2 import cv2
image=cv2.imread(“E:/Drive/msc/anshucln/Images/420.jpg”)
gray_image=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
inverted=255-gray_image
blurred=cv2.GaussianBlur(inverted,(21,21),0)
invertedblur=255-blurred
pencilsketch=cv2.divide(gray_image,invertedblur,scale=256.0)

cv2.imwrite(“E:/Drive/msc/anshucln/Images/42111.jpg”,pencilsketch)

Leave a Comment

error

Enjoy this blog? Please spread the word :)