By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
Notification Show More
Latest News
Passing a JavaScript Value Between HTML Pages
Passing a JavaScript Value Between HTML Pages
JavaScript
Compare Objects in an Array
JavaScript Problem: Compare Objects in an Array
JavaScript
Switching Name Order Using Capturing Groups in Regular Expressions
Switching Name Order Using Capturing Groups in Regular Expressions
JavaScript
Shuffling an Array
JavaScript Problem: How to Perform Shuffling an Array
JavaScript
Create a Non-duplicated Collection
JavaScript Problem: Using Set to Create a Non-duplicated Collection
JavaScript
Aa
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > Python > Convert Images Into Pencil Sketch Using Python
Python

Convert Images Into Pencil Sketch Using Python

Rohan750
Last updated: 2021/05/16 at 5:31 AM
Rohan750
Share
2 Min Read

In this python project, we will convert an image into a sketch file or add a sketch filter using python OpenCV.  This project will be fun, why? Because we will create this python program in just 5 lines.

Convert Images Into Pencil Sketch Using Python
So we will use a filter in python in just 4 simple steps.First, we have to add a grey filter to our image. Then we have to invert the filter to the grey image we have created. and then we have to add a blur effect to our inverted image. And after we create a sketch image.

so let’s get started now open your favorite code editor. And create a python file. After first import the OpenCV library like import cv2. And create an Image variable to store our image. After creating a grey_img variable for the add grey filter to our image. After adding a grey filter we have to invert our image. So create another variable invert. Then invert the image After adding a blur filter. So we create another variable blur. After adding a blur effect. Invert this blur effect.
so again create a variable inverted_blur. And last we have to add a filter which is a sketch. so create a sketch variable and call cv2.divide(grey_img,inverted_blur,scale=256.0)
Now we have to save our sketch image 
cv2.imwrite(“sketch.png”,sketch)

Note: make sure your file extension name is png otherwise it will not work.

syntax like:sketch.png



import cv2
image=cv2.imread("captain_Amreica.png")
grey_img=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
invert=cv2.bitwise_not(grey_img)
blur=cv2.GaussianBlur(invert,(21,21),0)
inverted_blur=cv2.bitwise_not(blur)
sketch=cv2.divide(grey_img,inverted_blur,scale=256.0)
cv2.imwrite("sketch.png",sketch)

watch the Python Projects – Convert Images Into Pencil Sketch Using Python (5 lines)


Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Bookmarker Application in javascript
Next Article C Programs Practicals
6 Comments 6 Comments
  • Merrill says:
    November 18, 2021 at 9:59 pm

    I do not know if it’s just me or if perhaps everyone else experiencing
    issues with your site. It appears as if some of the text in your content are running off the screen. Can somebody else please provide feedback and let
    me know if this is happening to them too? This might
    be a issue with my web browser because I’ve had this happen before.
    Many thanks

    Reply
  • ซุปเปอร์สล็อต says:
    March 9, 2022 at 4:27 am

    Say, you got a nice blog.Really looking forward to read more. Want more.

    Reply
  • Glynda Leblane says:
    May 2, 2022 at 7:12 am

    Woh I enjoy your articles, saved to favorites! .

    Reply
  • Xiao Lyke says:
    May 22, 2022 at 1:02 pm

    Keep functioning ,terrific job!

    Reply
  • Pingback: How To Make Python QR Code Generator - rocoderes
  • Pingback: How To Make Rock Paper Scissors Python Game 2022 - rocoderes

Leave a Reply Cancel reply

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

- Advertisement -

You Might Also Like

Rock Paper Scissors Python

How To Make Rock Paper Scissors Python Game 2022

November 26, 2022
python QR code generator

How To Make Python QR Code Generator

November 25, 2022
Countdown Calendar using Python Tkinter

How to Make Countdown Calendar using Python Tkinter

November 24, 2022
binary search algorithm in python

What is Binary Search Algorithm in python?

November 23, 2022
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?