当前位置:网站首页>[beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)
[beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)
2022-07-01 17:32:00 【Programmer pear】
Preface
author :“ Programmer pear ”
** The article brief introduction **: This article mainly calls Baidu interface to make a face value detection gadget .
** Article source code access **: In order to thank everyone who pays attention to me, the project source code of each article is distributed free of charge
Enjoy drops
Welcome friends give the thumbs-up 、 Collection 、 Leaving a message.
Text
Why these days , It's easy for everyone Appearance anxiety ? You want to know how many points you can give to a real face ?
Hey , Today, Xiaobian will make an application Baidu for you AI Face recognition function of the face value detection script ! Interested friends
Let's see the effect together ~
1) Effect display
Install well baidu-aip modular , Got Baidu AI After the interface key , You can call Baidu interface for face attribute recognition .
First, take the picture of Liu Yifei as an example to analyze the age 、 Gender 、 Identification of appearance value .

2) The source code to achieve
import os
import base64
from aip import AipFace
os.chdir(r'F:\ official account \28. Face recognition ')
# Set the path where the pictures are stored
pictureName = '1_yz.jpg'
def get_picture_content(pictureName):
with open(pictureName, 'rb') as fp:
content = base64.b64encode(fp.read())
return content.decode('utf-8')
# Define functions to read pictures
APP_ID = 'XXX'
API_KEY = 'XXXXXXXX'
SECRET_KEY = 'XXXXXXXXXXXX'
# Baidu account and key
options = {}
imageType = 'BASE64'
options["face_field"] = "age, gender, beauty"
aipFace = AipFace(APP_ID, API_KEY, SECRET_KEY)
result = aipFace.detect(get_picture_content(pictureName), imageType, options)
print(result)notes : among os.chdir The content in should be replaced by the address where you store the picture ,APP_ID、API_KEY、SECRET_KEY
It should be replaced by the baidu key you obtained at the end of Chapter 2 .
The results are as follows :

among ,age The corresponding value is age ,gender The corresponding value is gender ,beauty The corresponding value is face value score .
Output in standard format for further specification , Normalized by the following code :
import pandas as pdface_character = pd.DataFrame({"age":[result['result']['face_list'][0]['age']], "gender":[result['result']['face_list'][0]['gender']['type']], "beauty":[result['result']['face_list'][0]['beauty']] })
The results are as follows :

It can be found that Liu Yifei's appearance is very important to this result , I'm surprised, too , So the selfie score should be regarded as entertainment !!
Optimized source code ——
import os
import re
import time
import base64
import pandas as pd
import tkinter as tk
from aip import AipFace
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
Folderpath = filedialog.askdirectory(title = ' Please select the folder where the pictures are stored ')
picturePath = filedialog.askopenfilename(title = ' Please select the image to be evaluated ')
root.destroy()
os.chdir(Folderpath)
# Set the path where the pictures are stored
def get_picture_content(picturePath):
with open(picturePath, 'rb') as fp:
content = base64.b64encode(fp.read())
return content.decode()
# Define functions to read pictures
APP_ID = 'XXX'
API_KEY = 'XXXXXXXX'
SECRET_KEY = 'XXXXXXXXXXXX'
# Baidu account and key
options = {}
options["max_face_num"] = 2
options["face_field"] = "gender"
aipFace = AipFace(APP_ID, API_KEY, SECRET_KEY)
imageType = 'BASE64'
result = aipFace.detect(get_picture_content(picturePath), imageType, options)
gender = result['result']['face_list'][0]['gender']['type']
options["face_field"] = "age"
time.sleep(1)
result = aipFace.detect(get_picture_content(picturePath), imageType, options)
age = result['result']['face_list'][0]['age']
options["face_field"] = "beauty"
time.sleep(2)
result = aipFace.detect(get_picture_content(picturePath), imageType, options)
beauty = result['result']['face_list'][0]['beauty']
# For age 、 Gender 、 Beauty information
face_character = pd.DataFrame({"age":age, "gender":gender, "beauty":beauty},index = ['value'])
if face_character['beauty'][0]>80:
if face_character['gender'][0] == 'female':
str_list = " Young lady :"+ str(age) + ", The beauty of the watch "+ ', The final appearance value score is :'+str(beauty)
else:
str_list = " Little brother guigeng :"+ str(age) + ", The beauty of the watch "+ ', The final appearance value score is :'+str(beauty)
elif face_character['beauty'][0]>70:
if face_character['gender'][0] == 'female':
str_list = " Young lady :"+ str(age) + ", Natural beauty "+ ', The final appearance value score is :'+str(beauty)
else:
str_list = " Little brother guigeng :"+ str(age) + ", Natural beauty "+ ', The final appearance value score is :'+str(beauty)
elif face_character['beauty'][0]>50:
if face_character['gender'][0] == 'female':
str_list = " Young lady :"+ str(age) + ", Fair appearance "+ ', The final appearance value score is :'+str(beauty)
else:
str_list = " Little brother guigeng :"+ str(age) + ", Fair appearance "+ ', The final appearance value score is :'+str(beauty)
elif face_character['beauty'][0]>30:
if face_character['gender'][0] == 'female':
str_list = " Young lady :"+ str(age) + ", Congenital is not enough , The day after tomorrow "+ ', The final appearance value score is :'+str(beauty)
else:
str_list = " Little brother guigeng :"+ str(age) + ", Congenital is not enough , The day after tomorrow " + ', The final appearance value score is :'+str(beauty)
else:
if face_character['gender'][0] == 'female':
str_list = " Young lady :"+ str(age) + ", Go to bed early "+ ', The final appearance value score is :'+str(beauty)
else:
str_list = " Little brother guigeng :"+ str(age) + ", Go to bed early "+ ', The final appearance value score is :'+str(beauty)
# Face value definition
from tkinter import *
from PIL import Image, ImageTk
from win32com.client import Dispatch
# Import package
speaker = Dispatch("SAPI.SpVoice")
def roll_call():
speaker.Speak(str_list)
# Control playback voice
os.chdir(Folderpath)
# Set file path
root = Tk()
root.title(" Color value test applet ")
root.iconbitmap("pikaqiu2.ico")
# Settings window
image = Image.open(picturePath)
# Loading pictures
root.geometry("400x300")
# Set the window size according to the picture size
img_pic = ImageTk.PhotoImage(image)
label = Label(root, image=img_pic)
label.pack()
b2 = tk.Button(root, bg='lightyellow', text=' Beauty evaluation ', font=("KaiTi", 8), width=8, height=2, command=roll_call)
b2.place(x=0, y=0)
root.mainloop()Star test ——
1) Jia Ling

Appearance evaluation results :
' Young lady :29, Congenital is not enough , The day after tomorrow , The final appearance value score is :30.67'The appearance value score is for reference only , Don't take it seriously .
Some of my photos are more than 30 points , Probably with the background 、 The light 、 Expression has a certain relationship , We treat it as entertainment
good .
2) Xiao Zhan

Appearance evaluation results :
' Little brother guigeng :23, Fair appearance , The final appearance value score is :63.9'The appearance value score is for reference only , Don't take it seriously , If you think there is a problem with my code, you can download the pictures and code to try . wry smile !
summary
The appearance value score is for reference only , Don't take it seriously

From the appearance score above, we can find , The general appearance score is low , More than 80 points have been counted as high scores , All right. ! Call Baidu interface
Face recognition has been explained , Interested friends can do it by themselves

Note: Xiaobian can get more wonderful content ! Remember to click on the portal
Remember Sanlian ! If you need packaged source code + Free sharing of materials !! Portal
边栏推荐
- SQL injection vulnerability (MySQL and MSSQL features)
- [splishsplash] about how to receive / display user parameters, MVC mode and genparam on GUI and JSON
- String class
- C language implementation of sum of two numbers [easy to understand]
- (16) ADC conversion experiment
- Roewe rx5's "a little more" product strategy
- Transition technology from IPv4 to IPv6
- Replace UUID, nanoid is faster and safer!
- SQL注入漏洞(Mysql与MSSQL特性)
- 中国冰淇淋市场深度评估及发展趋势预测报告(2022版)
猜你喜欢

(27) Open operation, close operation, morphological gradient, top hat, black hat

Heavy disclosure! Hundreds of important information systems have been invaded, and the host has become a key attack target

Official announcement! Hong Kong University of science and Technology (Guangzhou) approved!

重磅披露!上百个重要信息系统被入侵,主机成为重点攻击目标

DNS
![[splishsplash] about how to receive / display user parameters, MVC mode and genparam on GUI and JSON](/img/83/9bd9ce7608ebfe7207ac008b9e8ab1.png)
[splishsplash] about how to receive / display user parameters, MVC mode and genparam on GUI and JSON
![[Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①](/img/24/23f6534e2c74724f9512c5b18661b6.png)
[Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①
![[C supplement] [string] display the schedule of a month by date](/img/9c/5fcc6bfc8fe0f433c0d1eba92b5c3e.jpg)
[C supplement] [string] display the schedule of a month by date

Transition technology from IPv4 to IPv6

Countdownlatch blocking wait for multithreading concurrency
随机推荐
How to write good code - Defensive Programming Guide
麦趣尔:媒体报道所涉两批次产品已下架封存,受理消费者诉求
The difference and relationship between iteratible objects, iterators and generators
Gameframework eating guide
中国酶制剂市场预测与投资战略研究报告(2022版)
Shenyu gateway development: enable and run locally
(12) About time-consuming printing
Girls who want to do software testing look here
There is a new breakthrough in quantum field: the duration of quantum state can exceed 5 seconds
Vulnhub range hacksudo Thor
Is it reasonable and safe to open a securities account for 10000 shares free of charge? How to say
荣威 RX5 的「多一点」产品策略
SQL injection vulnerability (MySQL and MSSQL features)
PETRv2:一个多摄像头图像3D感知的统一框架
In aks, use secret in CSI driver mount key vault
China PBAT resin Market Forecast and Strategic Research Report (2022 Edition)
走进微信小程序
换掉UUID,NanoID更快更安全!
[Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①
[Supplément linguistique c] déterminer quel jour est demain (date de demain)
