Convert Image Into Sketch using Python
![](https://codewithcurious.com/wp-content/uploads/2022/11/thumbnail-6-768x432.png)
In This Article, we’ll learn how to convert an image into a pencil sketch using python and CV2. CV2 is a python Module for OpenCV python. OpenCV has a function to read video, which is cv2. VideoCapture() also we can access the webcam using the CV2.
In this Tutorial for Generating the pencil sketch, we’ll first Convert the image into a gray image. then the gray image is converted into the inverted image after that generated inverted image is converted into the blurred image then they converted into the invertblur and finally the sketch image is generated.
Checkout the below images you’ll get an idea.
![](https://codewithcurious.com/wp-content/uploads/2022/11/iron.jpeg)
![](https://codewithcurious.com/wp-content/uploads/2022/11/Sketch1.png)
![](https://codewithcurious.com/wp-content/uploads/2022/11/Sketch2.png)
![](https://codewithcurious.com/wp-content/uploads/2022/11/Sketch.png)
Installation of CV2:
$ pip install opencv-python
Code:
# Importing the Required Moduel
# Codewithcurious.com
import cv2 as cv
# Reading the image
# Replace this image name to your image name
image = cv.imread("iron.jpeg")
# Converting the Image into gray_image
gray_image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
# Inverting the Imge
invert_image = cv.bitwise_not(gray_image)
# Blur Image
blur_image = cv.GaussianBlur(invert_image, (21,21), 0)
# Inverting the Blured Image
invert_blur = cv.bitwise_not(blur_image)
# Convert Image Into sketch
sketch = cv.divide(gray_image, invert_blur, scale=256.0)
# Generating the Sketch Image Named as Sketch.png
cv.imwrite("Sketch4.png", invert_blur)
Output:
![](https://codewithcurious.com/wp-content/uploads/2022/11/Handwritten-Notes-15-1024x576.png)
Find More Projects
Resume Builder Application using Java With Source Code Graphical User Interface [GUI] Introduction: The Resume Builder Application is a powerful and user-friendly …
Encryption Tool using java with complete source Code GUI Introduction: The Encryption Tool is a Java-based GUI application designed to help users …
Movie Ticket Booking System using Java With Source Code Graphical User Interface [GUI] Introduction: The Movie Ticket Booking System is a Java …
Video Call Website Using HTML, CSS, and JavaScript (Source Code) Introduction Hello friends, welcome to today’s new blog post. Today we have …
promise day using html CSS and JavaScript Introduction Hello all my developers friends my name is Gautam and everyone is welcome to …
Age Calculator Using HTML, CSS, and JavaScript Introduction Hello friends, my name is Gautam and you are all welcome to today’s new …