TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial…

Member-only story

Generate Pencil Sketch from Photo in Python

Abhijith Chandradas
TDS Archive
Published in
4 min readJul 29, 2021

--

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.’

Photo by Raamin ka on Unsplash

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…

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Abhijith Chandradas
Abhijith Chandradas

Written by Abhijith Chandradas

Data Analyst | Hacker | Financial Analyst | Freelancer | IIM MBA | Opensource | Democratize Knowledge | https://www.youtube.com/channel/UCLpBd4gzfIBXm2BPpdHOWdQ

Responses (1)