Convert Image Into Sketch using Python

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.

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:

Find More Projects

e-commerce management system in java Introduction The e-commerce management system is a GUI-based desktop application designed using Java swing in Netbean IDE. …

time table generator in java introduction The Time Table Generator is a Java utility that helps educational institutions automatically create class schedules …

crime record management system in java introduction The Crime Record Management System is a secure and systematic way of maintaining criminal and …

car rental system in java(GUI swing) introduction The Car Rental System is a Java application tailored for vehicle rental agencies. It allows …

food delivery management system in java introduction This Food Delivery Management System helps restaurants manage customer orders, menus, deliveries, and billing using …

online course registration in java introduction The Online Course Registration System allows students to enroll in courses using a Java application with …

Get Huge Discounts
More Python Projects

Leave a Comment

Your email address will not be published. Required fields are marked *