Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article is a series of three introductory Python projects. Beginners can try implementing these projects and get their hands dirty in a Python compilation environment.

🌟 [Python Introduction Project] Generate QR codes using Python 🌟 Use Tkinter’s Python calendar GUI application 🌟 use Python to convert images into pencil sketches

@[TOC](🏆 Convert a student’s photo into a pencil sketch using Python)

It’ll be fun. We’ll write the code step by step and explain it.

🥇 Step 1: Install the OpenCV library

We will use the OpenCV library in this project. Use the following command to install it.

pip install opencv-python
Copy the code

🍖 Step 2: Choose your favorite picture

Find the picture you want to convert to pencil sketch, here I will use the schoolgirl’s photo, you can choose any you want.

🚀 Step 3: Read images in RBG format

The RBG format image is read and then converted to a grayscale image. Now, the image is a classic black and white photograph.

import cv2
# fetch image
image = cv2.imread("dog.jpg")
Copy the code
# Convert the BGR image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
Copy the code

🥋 Step 4: Reverse grayscale image also known as negative image

An inverted grayscale image is also called a negative image, and this will be our inverted grayscale image. Inversions are basically used to enhance details.

# Image inversion
inverted_image = 255 - gray_image
Copy the code

🎻 Step 5: Create a pencil sketch

Finally, a pencil sketch is created by mixing a grayscale image with an inverted blur image. This is done by dividing a grayscale image by an inverted blur image.

blurred = cv2.GaussianBlur(inverted_image, (21.21), 0)
inverted_blurred = 255 - blurred
pencil_sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0)
Copy the code

We now have pen_Sketch. Then use OpenCV to display it.

cv2.imshow("Original", image)
cv2.imshow("Pencil Sketch", pencil_sketch)
cv2.waitKey(0)
Copy the code

Output:

All the code is done here, you just need to copy and paste it.

🎴 Lists more Python projects

Here’s a list of more Python projects I’ll try:

  1. Weight converter with GUI using Tkinter
  2. Send custom email using Python
  3. Unique password generator GUI
  4. Convert text to speech in Python
  5. Fetching data from web sites
  6. Rock-paper-scissors game
  7. Alarm clock with graphical user interface
  8. Python video downloader
  9. Python Web site blocker
  10. Python game

🛬 wuhu! Take off!

I’ve been writing technical blogs for a long time, mostly through Nuggets, and this is my tutorial on a Python applet. I like to share technology and happiness through articles. You can visit my blog at juejin.cn/user/204034… For more information. Hope you like it! 😊

This article is a series of three introductory Python projects. Beginners can try implementing these projects and get their hands dirty in a Python compilation environment.

🌟[[Python Introduction Project] Generating QR codes using Python] 🌟[Python Calendar GUI application using Tkinter] 🌟 Converts images to pencil sketches using Python

🥇 past quality articles

❤️ Single-player AI minesweeper using Python ❤️ [Python Introduction Project] Generate qr codes using Python ❤️ Simple analog clock ❤️ using HTML, CSS and JavaScript Make a random password generator ❤️ Make a great weather Web application using HTML, CSS, JS and API ❤️ Are you really proficient with HTML5 and how many of these 10 cool H5 features do you know? ❤️ how to design a Neumorphism style digital clock in JavaScript

📣 Endnote: Python is a very easy language to learn because of its simple syntax. We’ve only covered basic Python projects here. If you want to learn more about Python, you can follow me: Haiyong, I hope you found this article helpful.

If you see this, thank you for reading 🙂

💌 welcomes your comments and suggestions in the comments section! 💌

If you really learn something new from this article, like it, bookmark it and share it with your friends. 🤗 and finally, don’t forget ❤ or 📑.