当前位置:网站首页>[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
边栏推荐
- Gameframework eating guide
- [Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①
- 深度优先遍历和广度优先遍历[通俗易懂]
- SystemVerilog structure (II)
- [Supplément linguistique c] déterminer quel jour est demain (date de demain)
- ShenYu 网关开发:在本地启用运行
- Vulnhub range hacker_ Kid-v1.0.1
- JDBC:深入理解PreparedStatement和Statement[通俗易懂]
- Replace UUID, nanoid is faster and safer!
- How to use etcd to realize distributed /etc directory
猜你喜欢

ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享

(28) Shape matching based on contour features

There is a new breakthrough in quantum field: the duration of quantum state can exceed 5 seconds

整形数组合并【JS】

New patent applications and transfers

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

Jojogan practice

The difference and relationship between iteratible objects, iterators and generators

GameFramework食用指南

In aks, use secret in CSI driver mount key vault
随机推荐
PHP implements sensitive word filtering system "suggestions collection"
There is a new breakthrough in quantum field: the duration of quantum state can exceed 5 seconds
ACM mm 2022 video understanding challenge video classification track champion autox team technology sharing
China BMS battery management system Market Research Report (2022 Edition)
C language implementation of sum of two numbers [easy to understand]
【Try to Hack】vulnhub DC4
How to use etcd to realize distributed /etc directory
Euler function: find the number of numbers less than or equal to N and coprime with n
[C language foundation] 12 strings
【C语言补充】判断明天是哪一天(明天的日期)
Soft test software designer full truth simulation question (including answer analysis)
China PBAT resin Market Forecast and Strategic Research Report (2022 Edition)
JDBC: deep understanding of Preparedstatement and statement[easy to understand]
China biodegradable plastics market forecast and investment strategy report (2022 Edition)
unity3d扩展工具栏
National Security Agency (NSA) "sour Fox" vulnerability attack weapon platform technical analysis report
JDBC:深入理解PreparedStatement和Statement[通俗易懂]
Pyqt5, draw a histogram on the control
Intelligent operation and maintenance practice: banking business process and single transaction tracking
Detailed explanation of string's trim() and substring()
