当前位置:网站首页>[appearance detection artifact] come on, please show me your unique skill (is this appearance worthy of the audience?)
[appearance detection artifact] come on, please show me your unique skill (is this appearance worthy of the audience?)
2022-06-10 23:59: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
边栏推荐
- 【 pygame Games 】 don't find, Leisure Games Theme come 丨 Bubble Dragon applet - - Leisure Games Development recommendation
- 示波器刷新率怎么测量
- 判等问题:如何确定程序的判断是正确的?
- OpenResty安装
- 【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)
- 【Opencv实战】这个印章“神器”够牛,节省了时间提高了效率,厉害~(附完整源码)
- 【Pygame小游戏】“史上最炫酷贪吃蛇”驾到,FUN开玩(不好玩不要钱)
- Ilruntime hotfix framework installation and breakpoint debugging
- C# Tryparse的用法
- VS的常用设置
猜你喜欢

Unity 脚本无法显示C#源码的中文注释 或者VS创建的脚本没有C#源码的注释

都说验证码是爬虫中的一道坎,看我只用五行代码就突破它。

LabVIEW锁相环(PLL)

HyperLeger Fabric安装

LabVIEW执行串行回送测试

It is said that the verification code is a barrier in the crawler. I can break through it with only five lines of code.

LabVIEW获取Clamp函数找到的所有点的信息

【漫天烟花】绚烂烟花点亮夜空也太美了叭、某程序员携带烟花秀给大家拜年啦~

【Pygame小游戏】不怕你走不过系列:极致AI走迷宫,学习完带你打开新世界大门~(附游戏源码)

Opencv实战之图像的基本操作:这效果出来惊艳了众人(附代码解析)
随机推荐
Is it safe for changtou school to open an account? Is it reliable?
希尔排序
【AI出牌器】第一次见这么“刺激”的斗地主,胜率高的关键因素竟是......
LabVIEW and VDM extract color and generate gray image
MySQL command line import and export data
LabVIEW open other exe programs
MultipartFile重命名上传
MySQL命令行导入导出数据
Fiddler simulates low-speed network environment
Collection delete element technique removeif
Lambda 学习记录
【二叉树】二叉树剪枝
集合删除元素技巧 removeIf
启牛学堂理财可靠吗,安全吗
MySQL learning child query
File转为MultipartFile的方法
Common settings for vs
Insert sort
Easyrecovery15 simple and convenient data recovery tool
【Pygame小游戏】“史上最炫酷贪吃蛇”驾到,FUN开玩(不好玩不要钱)
