Draw the Sketch of Lionel Messi using a Python Program

Coloring sketch of Lionel Messi's face using a python program

Introduction

Today I'm gonna share with you how to draw a human face using a python module. Recently, I've created a python program to draw the sketch of my favorite footballer Lionel Messi, exactly like the original one.

Python offers a module called sketchpy (a python module for drawing an animation portrait of an image with Turtle), using that we can draw a few amounts of objects(including human faces, and country maps) only. Those come with the library inbuilt. 

But separately I decided to develop a python program to draw Messi's face uniquely. So, let's see how to transform this work into reality.

How does the program work?

Before we proceed, we need to find every single x-y coordinate of each point, around each part of the face (eyes, ears, hair, nose, nostril, chin, face outline, etc.) and so on. I've used a python program to find that (Check - How to get Coordinates of the Clicked Points on an Image). Then, we have to store those coordinates in separate text files for different objects(parts of the face) with different names.

Next, the imported turtle of our program will trace those points and draw one after one. We can set a different color for different parts also. I did that in my program. There is an online website(ImageResizer.com/color-picker) that offers to find out the RGB value of colors by selecting that (color) from an image

a website that offers to get hex code of a color from an image
Getting Hex Code

I've created a total of 48 text files (which store coordinates list) to draw Messi's Face and these must be required by the program.

Requirements

Use pip3 instead of pip, for Linux.

Install sketchpy: pip install sketchpy

Import the modules

Let's create a Python file with the name "Messi.py" and start writing the code by importing this module.


# Import canvas module from sketchpy
from sketchpy import canvas

Create an object

Create an object of canvas.sketch class. I named the object 'Turtle' for matching the name with the working principle.


# Create an object of canvas.sketch class
Turtle = canvas.sketch(x_offset=290, y_offset=320)

Call the Draw Function several times

You will see, I've called the 'draw_fn()' several times to draw different parts of the face and other objects. Let me introduce the arguments I passed in that function.

'draw_fn()' - takes the parameters like this:

draw_fn(file,mode = 1,co = (0,0,0),thickness = 1,retain = False)

Where, file - the path of the file which contains coordinates,

mode - mode of drawing(1 - sketch with a line, 0 - fill with color),

co - the color of the line or fill,

thickness (default) - thickness of the line (I didn't mention it in the program; in this case, the program takes the by-default option), and

retain (default) - retain the image drawn after executing.


# Outline of the face
Turtle.draw_fn("face_out", co=(233, 183, 151), mode=0)
# Outline of the Beard
Turtle.draw_fn("beard_out", co=(30, 25, 31), mode=0)

Turtle.draw_fn("chin1", co=(204, 139, 124), mode=0)
Turtle.draw_fn("chin2", co=(204, 139, 124), mode=0)

Turtle.draw_fn("lip_lower", co=(214, 125, 100), mode=0)
Turtle.draw_fn("lip_upper", co=(186, 30, 21), mode=0)

Turtle.draw_fn("nostril", co=(8, 15, 29), mode=0)
Turtle.draw_fn("nose_curve", co=(128, 69, 56), mode=0)
Turtle.draw_fn("right_eyebrow", co=(12, 16, 22), mode=0)
Turtle.draw_fn("left_eyebrow", co=(12, 16, 22), mode=0)

Turtle.draw_fn("noseline", co=(12, 16, 22), mode=0)

Turtle.draw_fn("eyelid", co=(13, 15, 23), mode=0)
Turtle.draw_fn("eye", co=(17, 12, 20), mode=0)
Turtle.draw_fn("sclera", co=(230, 231, 229), mode=0)
Turtle.draw_fn("eyeball", co=(15, 25, 15), mode=0)
Turtle.draw_fn("eyeball_centre", co=(230, 231, 229), mode=0)

Turtle.draw_fn("hair_outline", co=(12, 16, 25), mode=0)
Turtle.draw_fn("hair_shade1", co=(12, 16, 25), mode=0)
Turtle.draw_fn("hair_shade2", co=(61, 44, 52), mode=0)
Turtle.draw_fn("hair_shade3", co=(119, 64, 75), mode=0)
Turtle.draw_fn("hair_shade4", co=(119, 64, 75), mode=0)
Turtle.draw_fn("hair_shade5", co=(61, 44, 52), mode=0)
Turtle.draw_fn("hair_shade6", co=(119, 64, 75), mode=0)
Turtle.draw_fn("hair_shade7", co=(61, 44, 52), mode=0)
Turtle.draw_fn("hair_shade8", co=(61, 44, 52), mode=0)

Turtle.draw_fn("throat", co=(245, 207, 171), mode=0)
Turtle.draw_fn("throat_shade1", co=(236, 180, 153), mode=0)
Turtle.draw_fn("throat_shade2", co=(236, 180, 153), mode=0)

Turtle.draw_fn("ear_line1", co=(16, 10, 8), mode=0)
Turtle.draw_fn("ear_line2", co=(16, 10, 8), mode=0)
Turtle.draw_fn("ear_line3", co=(16, 10, 8), mode=0)
Turtle.draw_fn("ear_shade1", co=(212, 138, 124), mode=0)
Turtle.draw_fn("ear_shade2", co=(212, 138, 124), mode=0)
Turtle.draw_fn("ear_shade3", co=(212, 134, 122), mode=0)

Turtle.draw_fn("beard_shade1", co=(124, 77, 75), mode=0)
Turtle.draw_fn("beard_shade2", co=(127, 76, 76), mode=0)

Turtle.draw_fn("face_shade1", co=(209, 137, 122), mode=0)
Turtle.draw_fn("face_shade2", co=(208, 138, 119), mode=0)

Turtle.draw_fn("eye_shade1", co=(209, 143, 126), mode=0)
Turtle.draw_fn("eye_shade2", co=(209, 143, 126), mode=0)

Turtle.draw_fn("face_shade3", co=(245, 207, 171), mode=0)
Turtle.draw_fn("face_shade4", co=(240, 208, 169), mode=0)

Turtle.draw_fn("forhead_shade1", co=(202, 135, 119), mode=0)

Turtle.draw_fn("tshirt", co=(0, 30, 82), mode=0)
Turtle.draw_fn("tshirt_color1", co=(193, 36, 57), mode=0)
Turtle.draw_fn("tshirt_color2", co=(4, 31, 138), mode=0)
Turtle.draw_fn("tshirt_color3", co=(3, 35, 180), mode=0)

Turtle.draw_fn("end", retain=True, co=(230, 239, 234), mode=0)

Look, in the above program, I passed a different text file as an argument for each calling of the 'draw_fn()' function. I named each file meaningful so that it would be easy to understand

These files must be placed in the folder/directory where the 'Messi.py' file is in. Each text file contains a large number of coordinates list. Get those from my GitHub page, through the 'Download' Button below.

Download the Project File

Get the text files used in the above program, from my GitHub page (https://github.com/subhankar-rakshit) through the download button.

Summary

In this tutorial, I narrated, how to draw human faces (or any objects) with the help of python programming. Here, I have drawn the sketch of my favorite footballer Lionel Messi using that Program.

I covered every single requirement through the separate post, videos, and information needed to complete this task.

Hope you loved this topic. Please leave your comments below in case of any doubts or problems related to this topic. You will get a reply soon.

To get more lovely python topics, visit the separate page created only for Unique Examples. Some examples are given below.

👉Communicate with Your Friends Secretly using Python

👉Blurring an image in Python - using OpenCV and Pillow library

👉Extract Metadata from an Image using Python

👉Check the strength of your password using python

Thanks for reading!💙

PySeek

Subhankar Rakshit

Meet Subhankar Rakshit, a Computer Science postgraduate (M.Sc.) and the creator of PySeek. Subhankar is a programmer, specializes in Python language. With a several years of experience under his belt, he has developed a deep understanding of software development. He enjoys writing blogs on various topics related to Computer Science, Python Programming, and Software Development.

1 Comments

  1. The program uses several text files to draw each part of the face. Each text file contains a large number of coordinates list.
    These files must be placed in the folder/directory where the 'Messi.py' file is in.

    Before the Conclusion, you'll find a download button that links to my GitHub page.
    Download the zip file from there, extract that; You'll get your desired result.

    ReplyDelete
Post a Comment
Previous Post Next Post