PENCIL SKETCHING in Python ..

 You don't need Snapchat to covert your image to pencil-sketched image ..

All you need is Python .. :)

All you need is a picture in the same directory ..

My image  


You can choose any image you want ..

import cv2            # pip install opencv-python
filename = 'av.jpg'   # the picture
img = cv2.imread(filename)    # reading the image

gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)    # changing BGR to Gray
inverted_gray_image = 255 - gray_image                # inverting the Gray color
blurred_img = cv2.GaussianBlur(inverted_gray_image, (21,21),0) # blurring the image
inverted_blurred_img = 255 - blurred_img              # inverting the blurred image
pencil_sketch_IMG = cv2.divide(gray_image, inverted_blurred_img, scale = 256.0)

#Show the original image
cv2.imshow('Original Image', img) # displaying the original image

#Show the new image pencil sketch
cv2.imshow('Pencil Sketch', pencil_sketch_IMG) # displaying the new image

cv2.waitKey(0)

And the output ..






Comments

Popular posts from this blog

2048 game in Python ..

Random Password Generator in Python ..

PACMAN in Python ..