当前位置:网站首页>[face recognition series] | realize automatic makeup
[face recognition series] | realize automatic makeup
2022-07-06 04:14:00 【Aasee.】
List of articles
Make up
Today's project is more interesting , Make up the face in the picture [ A bad laugh ], Think about when your girlfriend said that she forgot to apply lipstick and trim her eyebrows when taking photos today , Then you say you come , Give him a boast about the operation results P It's even uglier , This doesn't make lanterns in the toilet – Looking for shit , But don't panic. I'll save you today , Cough, get to the point .
First , We still have to know what functions we need to use first , It mainly uses these two face_landmarks( As mentioned in the last article , But for better experience and faster understanding, I'd better get it for you ),ImageDraw.polygon.
Face feature extraction function ——face_landmarks
face_landmarks( face_image , face_locations=None, model=“large” ) Given an image , Extract the facial feature position of each face in the image Parameters : face_image : Input face image face_locations=None : Optional parameters , The default value is None, Represents everyone's face in the default decoded picture . If input face_locations()[i] You can specify a face to decode model=“large” : Output feature model , The default is “large”, Optional “small”. When the choice is "small" when , Only the left eye is extracted left_eye、 Right eye right_eye、 Nose nose_tip These three facial features .
ImageDraw.polygon
Construct a ImageDraw object : polygon() Method is used to draw polygons : The first parameter is the number of polygons Composed of vertex positions list, The second parameter fill Is the face that fills the polygon color . line() The method is used to draw line segments composed of multiple points , The first parameter is Point position list, The second parameter fill Is the color of the line segment , The third reference Count width Is the width of the line segment .
By using face_landmarks To locate the characteristic face of the face , Use it Image.polygon Draw polygon , Next, the detailed code explanation
Specific code
import face_recognition
from PIL import Image, ImageDraw
def demoFunc2(pic_path):
# Load the picture as numpy Array
image = face_recognition.load_image_file(pic_path)
face_landmarks_list = face_recognition.face_landmarks(image)
print(f"I found {
len(face_landmarks_list)} face<s> in this photograph."))
pil_image = Image.fromarray(image)
# Traverse the face , draw
for face_landmarks in face_landmarks_list:
demo = ImageDraw.Draw(pil_image, 'RGBA')
demo.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128))
demo.polygon(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 128))
# demo.line(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 150), width=2)
# demo.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=2)
demo.polygon(face_landmarks['top_lip'], fill=(150, 0, 0, 128))
# demo.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128))
demo.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128))
# demo.line(face_landmarks['top_lip'], fill=(150, 0, 0, 64), width=2)
# demo.line(face_landmarks['bottom_lip'], fill=(150, 0, 0, 64), width=2)
demo.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30))
demo.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30))
# pil_image.save("1_.jpg") # have access to save Method to save
pil_image.show()
demoFunc2("6.png")
I found the use of line The method is a little strange after tracing , So I made a deletion here , You can also try it yourself , The color can also follow RGBA Try to change by yourself , I continue to use Peng Yuyan here to show you haha
Result display
At the same time, I also packed it to my github In the , If you want to play, you can also download it directly .
边栏推荐
- Stack and queue
- MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
- Lambda expression learning
- Data processing methods - smote series and adasyn
- Lora gateway Ethernet transmission
- 【leetcode】1189. Maximum number of "balloons"
- 【按鍵消抖】基於FPGA的按鍵消抖模塊開發
- ESP32_ FreeRTOS_ Arduino_ 1_ Create task
- POI add border
- MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
猜你喜欢
Solution to the problem that the root account of MySQL database cannot be logged in remotely
Proof of Stirling formula
Lora gateway Ethernet transmission
MySql数据库root账户无法远程登陆解决办法
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
VNCTF2022 WriteUp
Record the pit of NETCORE's memory surge
[disassembly] a visual air fryer. By the way, analyze the internal circuit
绑定在游戏对象上的脚本的执行顺序
Stable Huawei micro certification, stable Huawei cloud database service practice
随机推荐
Use js to complete an LRU cache
P2648 make money
Record the pit of NETCORE's memory surge
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
About some basic DP -- those things about coins (the basic introduction of DP)
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
Solution to the problem that the root account of MySQL database cannot be logged in remotely
Basic knowledge of binary tree, BFC, DFS
2327. 知道秘密的人数(递推)
2328. 网格图中递增路径的数目(记忆化搜索)
In Net 6 CS more concise method
asp. Core is compatible with both JWT authentication and cookies authentication
P2102 地砖铺设(dfs&贪心)
WPF effect Article 191 box selection listbox
lora网关以太网传输
Record an excel xxE vulnerability
One question per day (Mathematics)
How to execute an SQL statement in MySQL
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)