Python 3 Script to Convert Image to Pencil Sketch Using OpenCV Library Full Project For Beginners

Python 3 Script to Convert Image to Pencil Sketch Using OpenCV Library Full Project For Beginners

 

 

 

Installation

 

 

 

In order to get started we need to install python-opencv library using pip command

 

pip install python-opencv

 

 

Now we need to make a app.py and copy paste the following code

 

 

app.py

 

 

 

import cv2

image = cv2.imread("input.jfif")

grey_img = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

invert = cv2.bitwise_not(grey_img)

blur = cv2.GaussianBlur(invert,(21,21),0)

invertedblur = cv2.bitwise_not(blur)

sketch = cv2.divide(grey_img,invertedblur,scale=256.0)

cv2.imwrite("sketch.png",sketch)

 

 

 

Input Image File

 

 

 

 

 

Output Pencil Sketch Image

 

 

 

 

 

Leave a Reply