当前位置:网站首页>[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 .
边栏推荐
- 自动化测试的好处
- HotSpot VM
- 查询mysql数据库中各表记录数大小
- lora网关以太网传输
- 综合能力测评系统
- 软考 系统架构设计师 简明教程 | 总目录
- Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
- Class A, B, C networks and subnet masks in IPv4
- Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
- Several important classes in unity
猜你喜欢

When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation

Mysql数据库慢sql抓取与分析

math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
![[adjustable delay network] development of FPGA based adjustable delay network system Verilog](/img/82/7ff7f99f5164f91fab7713978cf720.png)
[adjustable delay network] development of FPGA based adjustable delay network system Verilog

电脑钉钉怎么调整声音

Basic knowledge of binary tree, BFC, DFS

Chinese brand hybrid technology: there is no best technical route, only better products

Basic use of MySQL (it is recommended to read and recite the content)

DM8 backup set deletion

SSTI template injection explanation and real problem practice
随机推荐
【leetcode】1189. Maximum number of "balloons"
Recommendation system (IX) PNN model (product based neural networks)
QML和QWidget混合开发(初探)
asp. Core is compatible with both JWT authentication and cookies authentication
Basic knowledge of binary tree, BFC, DFS
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
[Key shake elimination] development of key shake elimination module based on FPGA
Web components series (VII) -- life cycle of custom components
729. 我的日程安排表 I(set or 动态开点线段树)
Viewing and verifying backup sets using dmrman
Record the pit of NETCORE's memory surge
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
20、 EEPROM memory (AT24C02) (similar to AD)
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
WPF effect Article 191 box selection listbox
Record an excel xxE vulnerability
MySql数据库root账户无法远程登陆解决办法
Comprehensive ability evaluation system