Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Learn to use Python for "beauty" functionality


Jun 01, 2021 Article blog



This article was reproduced to Know ID: Charles (Bai Lu) knows his personal column

Download the W3Cschool Mobile App, 0 Foundation Anytime, Anywhere Learning Programming >> Poke this to learn

Lead

Use Python to achieve beauty...

This is a project that was previously downloaded on GitHub...

There seems to be some days...

So I can't find the link to the original project for the time being...

Today took the time to look at the main idea of its source code, it seems quite simple...

So I decided to use Python 3 to make a comeback on my own...

T_T it still feels interesting...

Just have a try!


Related documents

File download link: https://pan.baidu.com/s/18-mGsw0VeQxaQJ7Ljiqowg

Password: 6rd8


Develop tools

Python version: 3.5.4

Related modules:

numpy module;

cv2 module;

dlib module.

Environment construction

Install Python and add it to the environment variable, and pip installs the relevant modules that are required.

Note 1:

cv2 is the opencv-python module.

Note 2:

The dlib module can be installed directly under anaconda3, otherwise it is prone to errors. A compiled version of python 3.5 whl file is available in the relevant file for installation by non-anaconda3 users.


The main idea

statement:

The main idea is based on the project source code speculation, is not my idea, I hope I did not guess wrong.

Feature extraction:

Using the dlib library to extract facial features, facial feature points include:

Chin, mouth, nose, left and right eyes, left and right ears and other parts.

Specific beautification operations for different parts of the face.

In addition, because the dlib library can not extract the boundary coordinates of the forehead, and the beauty of the forehead is also very important...

So suppose the forehead is near the brow, and an ellipse is made with the corresponding parameters as a rough estimate of the forehead.

In practice, the five-in-a-side coincidement part needs to be removed and only the same part as the skin tone of the nose retained.

Beautification method:

It's very common whitening, adding brightness, grinding and sharpening.

Whitening and increasing brightness are achieved in HSV space;

The grinding is made with Gauss filters and bilateral filters;

Sharpening uses convolutional sharpening algorithms.

The implementation process can be found in the source code.


Use the demo

illustrate:

According to their own needs to call the corresponding beautification method to achieve beauty.

The default parameters are for reference only, based on the actual effect, you can adjust some parameters yourself to make the effect look better.

How to use it:

Run the Beauty.py file in the cmd window.

The photo path to be processed is in line 232 of the source code, please modify it yourself.

Demo 1:

 Learn to use Python for "beauty" functionality1

Failure 2:

 Learn to use Python for "beauty" functionality2

Failure 3:

 Learn to use Python for "beauty" functionality3

T_T okay effect is more general...


more

Overall... The effect is more general...

At the same time I found that some head shape is not suitable for the beauty of this algorithm... /b10> For example, I tried a picture of Jack Ma... T he result is not very OK...

And the parameters don't seem to be very well tuned...

It might be a lot better to make Demo...

Interested friends can try to do a Meitu show highly non-imitation version.

T_T, that's it.