Member-only story
Generate Pencil Sketch from Photo in Python
Image manipulation using OpenCV tutorial with code
Import Libraries
OpenCV is the only library which is needed for the project.
We will also be using matplotlib library for some visualizations which is discussed later.
import cv2
import matplotlib.pyplot as plt
Read Photo
The following command can be used to read image using OpenCV.
img=cv2.imread("photo.jpg")
This command reads the file photo.jpg located in the current folder and stores in memory as img.
Show Image using OpenCV
Displaying image using OpenCV is not very straight forward. The following command can be used to display the photo.
cv2.imshow(‘original image’,img)
cv2.waitKey(0)
cv2.destroyAllWindows()
When this command is executed, the below photo will open in a new window with title as ‘original image.’
Display Using Matplotlib
It is not very convenient when new window opens up every time image has to be displayed and also the new window has to be deleted for further execution of code.
To avoid…