当前位置:网站首页>[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
边栏推荐
- Mysql database - Advanced SQL statement (2)
- National Security Agency (NSA) "sour Fox" vulnerability attack weapon platform technical analysis report
- Euler function: find the number of numbers less than or equal to N and coprime with n
- ShenYu 网关开发:在本地启用运行
- [splishsplash] about how to receive / display user parameters, MVC mode and genparam on GUI and JSON
- Vulnhub range hacksudo Thor
- 中国一次性卫生用品生产设备行业深度调研报告(2022版)
- Radhat builds intranet Yum source server
- 中国酶制剂市场预测与投资战略研究报告(2022版)
- 《中国智慧环保产业发展监测与投资前景研究报告(2022版)》
猜你喜欢
荣威 RX5 的「多一点」产品策略

(十七)DAC转换实验
![[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

换掉UUID,NanoID更快更安全!

如何写出好代码 — 防御式编程指南

Yyds dry inventory MySQL RC transaction isolation level implementation

Gameframework eating guide
![[C language foundation] 12 strings](/img/42/9c024eb08eb935fe66c3aaac7589d8.jpg)
[C language foundation] 12 strings

Intelligent operation and maintenance practice: banking business process and single transaction tracking

Gold, silver and four want to change jobs, so we should seize the time to make up
随机推荐
(17) DAC conversion experiment
Is the software of futures pioneer formal and safe? Which futures company is safer to choose?
Radhat builds intranet Yum source server
【C語言補充】判斷明天是哪一天(明天的日期)
JDBC: deep understanding of Preparedstatement and statement[easy to understand]
反射型XSS漏洞
中国氮化硅陶瓷基板行业研究与投资前景报告(2022版)
Code example of libcurl download file
[C supplement] [string] display the schedule of a month by date
中国PBAT树脂市场预测及战略研究报告(2022版)
Pyqt5, draw a histogram on the control
Develop those things: easycvr cluster device management page function display optimization
Vulnhub range hacker_ Kid-v1.0.1
(12) About time-consuming printing
Maizeer: the two batches of products reported by the media have been taken off the shelves and sealed, and consumer appeals are accepted
为什么你要考虑使用Prisma
DNS
换掉UUID,NanoID更快更安全!
荣威 RX5 的「多一点」产品策略
股票万1免5证券开户是合理安全的吗,怎么讲
