当前位置:网站首页>[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
边栏推荐
- 多线程并发之CountDownLatch阻塞等待
- Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
- unity3d扩展工具栏
- In depth evaluation and development trend prediction report of China's ice cream market (2022 Edition)
- 荣威 RX5 的「多一点」产品策略
- In aks, use secret in CSI driver mount key vault
- (27) Open operation, close operation, morphological gradient, top hat, black hat
- String class
- 提交review时ReviewBoard出现500错误解决方法
- 多线程使用不当导致的 OOM
猜你喜欢

【splishsplash】关于如何在GUI和json上接收/显示用户参数、MVC模式和GenParam

Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse

LeetCode中等题之TinyURL 的加密与解密

Pytest learning notes (13) -allure of allure Description () and @allure title()

Euler function: find the number of numbers less than or equal to N and coprime with n

换掉UUID,NanoID更快更安全!

【Try to Hack】vulnhub DC4

String class

ACL 2022 | 分解的元学习小样本命名实体识别

Girls who want to do software testing look here
随机推荐
Research Report on China's enzyme Market Forecast and investment strategy (2022 Edition)
China PBAT resin Market Forecast and Strategic Research Report (2022 Edition)
String的trim()和substring()详解
Computed property “xxx“ was assigned to but it has no setter.
China acetonitrile market forecast and strategic consulting research report (2022 Edition)
The reviewboard has 500 errors when submitting a review. Solutions
Alibaba cloud Li Feifei: China's cloud database has taken the lead in many mainstream technological innovations abroad
[wrung Ba wrung Ba is 20] [essay] why should I learn this in college?
存在安全隐患 起亚召回部分K3新能源
Yyds dry inventory MySQL RC transaction isolation level implementation
官宣!香港科技大学(广州)获批!
Official announcement! Hong Kong University of science and Technology (Guangzhou) approved!
中国冰淇淋市场深度评估及发展趋势预测报告(2022版)
ACL 2022 | 分解的元学习小样本命名实体识别
Object. fromEntries()
[mathematical modeling] [matlab] implementation of two-dimensional rectangular packing code
Is it reasonable and safe to open a securities account for 10000 shares free of charge? How to say
Report on research and investment prospects of UHMWPE industry in China (2022 Edition)
荣威 RX5 的「多一点」产品策略
ISO 27001 Information Security Management System Certification
