当前位置:网站首页>【颜值检测神器】来,请拿出你们的绝活(这颜值,对得起观众么?)
【颜值检测神器】来,请拿出你们的绝活(这颜值,对得起观众么?)
2022-06-10 22:42:00 【程序员梨子】
前言
作者 :“程序员梨子”
**文章简介 **:本篇文章主要调用百度接口制作一款颜值检测小工具啦。
**文章源码获取 **: 为了感谢每一个关注我的小可爱每篇文章的项目源码都是无偿分
享滴
点这里蓝色这行字体自取,需要什么源码记得说标题名字哈!私信我也可!
欢迎小伙伴们 点赞、收藏、留言
正文
为什么这年头,大家很容易外貌焦虑?想知道真实的颜值可以打多少分嘛?
嘿嘿,今天小编就来给大家制作一款应用百度AI的人脸识别功能的颜值检测小脚本啦!感兴趣的朋
友一起来看看效果吧~
1)效果展示
安装好baidu-aip模块,获取了百度AI接口密钥后,即可调用百度接口进行人脸属性识别了。
首先以刘亦菲的图片为例进行年龄、性别、颜值的识别。

2)源码实现
import os
import base64
from aip import AipFace
os.chdir(r'F:\公众号\28.人脸识别')
#设置图片存放的路径
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')
#定义读取图片的函数
APP_ID = 'XXX'
API_KEY = 'XXXXXXXX'
SECRET_KEY = 'XXXXXXXXXXXX'
#百度账号和密钥
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)注:其中os.chdir中的内容应该替换成你存储图片的地址,APP_ID、API_KEY、SECRET_KEY
应该替换成第二章末尾你获取的百度密钥。
得到结果如下:

其中,age对应的值为年龄,gender对应的值为性别,beauty对应的值为颜值分。
为进一步规范输出成标准格式,通过如下代码进行规范化:
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']] })
得到结果如下:

可以发现刘亦菲的颜值对于这个结果,我也比较吃惊,所以颜值得分大家当成娱乐就好!!
优化之后的源码——
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 = '请选择图片存放的文件夹')
picturePath = filedialog.askopenfilename(title = '请选择要进行颜值评价的图片')
root.destroy()
os.chdir(Folderpath)
#设置图片存放的路径
def get_picture_content(picturePath):
with open(picturePath, 'rb') as fp:
content = base64.b64encode(fp.read())
return content.decode()
#定义读取图片的函数
APP_ID = 'XXX'
API_KEY = 'XXXXXXXX'
SECRET_KEY = 'XXXXXXXXXXXX'
#百度账号和密钥
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']
#获取年龄、性别、颜值信息
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 = "小姐姐芳龄:"+ str(age) + ",颜值爆表"+ ',最终颜值得分为:'+str(beauty)
else:
str_list = "小哥哥贵庚:"+ str(age) + ",颜值爆表"+ ',最终颜值得分为:'+str(beauty)
elif face_character['beauty'][0]>70:
if face_character['gender'][0] == 'female':
str_list = "小姐姐芳龄:"+ str(age) + ",天生美颜"+ ',最终颜值得分为:'+str(beauty)
else:
str_list = "小哥哥贵庚:"+ str(age) + ",天生美颜"+ ',最终颜值得分为:'+str(beauty)
elif face_character['beauty'][0]>50:
if face_character['gender'][0] == 'female':
str_list = "小姐姐芳龄:"+ str(age) + ",颜值尚可"+ ',最终颜值得分为:'+str(beauty)
else:
str_list = "小哥哥贵庚:"+ str(age) + ",颜值尚可"+ ',最终颜值得分为:'+str(beauty)
elif face_character['beauty'][0]>30:
if face_character['gender'][0] == 'female':
str_list = "小姐姐芳龄:"+ str(age) + ",先天不够,后天来凑"+ ',最终颜值得分为:'+str(beauty)
else:
str_list = "小哥哥贵庚:"+ str(age) + ",先天不够,后天来凑" + ',最终颜值得分为:'+str(beauty)
else:
if face_character['gender'][0] == 'female':
str_list = "小姐姐芳龄:"+ str(age) + ",早点洗洗睡吧"+ ',最终颜值得分为:'+str(beauty)
else:
str_list = "小哥哥贵庚:"+ str(age) + ",早点洗洗睡吧"+ ',最终颜值得分为:'+str(beauty)
#颜值定义
from tkinter import *
from PIL import Image, ImageTk
from win32com.client import Dispatch
#导入包
speaker = Dispatch("SAPI.SpVoice")
def roll_call():
speaker.Speak(str_list)
#控制播放语音
os.chdir(Folderpath)
#设置文件路径
root = Tk()
root.title("颜值测试小程序")
root.iconbitmap("pikaqiu2.ico")
#设置窗口
image = Image.open(picturePath)
#加载图片
root.geometry("400x300")
#根据图片大小设置窗口大小
img_pic = ImageTk.PhotoImage(image)
label = Label(root, image=img_pic)
label.pack()
b2 = tk.Button(root, bg='lightyellow', text='颜值评价', font=("KaiTi", 8), width=8, height=2, command=roll_call)
b2.place(x=0, y=0)
root.mainloop()明星测试——
1)贾玲

颜值评价结果:
'小姐姐芳龄:29,先天不够,后天来凑,最终颜值得分为:30.67'颜值得分仅供参考,请勿当真。
我的有些照片测出来也是三十多分,可能跟背景、光线、表情都有一定的关系,大家当成娱乐就
好。
2)肖战

颜值评价结果:
'小哥哥贵庚:23,颜值尚可,最终颜值得分为:63.9'颜值得分仅供参考,请勿当真,认为我的代码有问题的可以自行下载图片和代码进行尝试。苦笑!
总结
颜值得分仅供参考,请勿当真

从上面的颜值得分可以发现,普遍颜值得分较低,八十多分的已经算高分了,好啦!调用百度接口
颜值识别已讲解完毕,感兴趣的朋友自己实现一遍吧

注小编获取更多精彩内容!记得点击传送门哈
记得三连哦! 如需打包好的源码+素材免费分享滴!!传送门
边栏推荐
- 上海网上开户是安全的吗?
- Hyperleger fabric installation
- MySQL learning child query
- [latex] latex vs Code Snippets
- SystemVerilog(十)-用户自定义类型
- LabVIEW obtains the information of all points found by the clamp function
- VS的常用设置
- IGBT与三代半导体SiC双脉冲测试方案
- 苹果CMS采集站源码-搭建教程-附带源码-全新源码-开发文档
- 【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)
猜你喜欢

LabVIEW使用MathScript Node或MATLAB脚本时出现错误1046

【无标题】

VS的常用设置

LabVIEW获取IMAQ Get Last Event坐标

自制APP连接OneNET---实现数据监控和下发控制(MQTT)

LabVIEW programming specification

LabVIEW change the shape or color of point ROI overlay
![The shell script of pagoda plan task regularly deletes all files under a directory [record]](/img/dc/cfd449bf14c4545cd2e52bda4ab31e.png)
The shell script of pagoda plan task regularly deletes all files under a directory [record]

OSS stores and exports related content

The serial port in the visa test panel under LabVIEW or max does not work
随机推荐
【Opencv实战】这个印章“神器”够牛,节省了时间提高了效率,厉害~(附完整源码)
快速排序
Binary tree pruning
It is known that the transverse grain pressure resistance of a certain wood obeys n (x, D2). Now ten specimens are tested for transverse grain pressure resistance, and the data are as follows: (unit:
The shell script of pagoda plan task regularly deletes all files under a directory [record]
启牛学堂理财可靠吗,安全吗
How to measure the refresh rate of oscilloscope
The serial port in the visa test panel under LabVIEW or max does not work
vtk. VTP download in JS
LabVIEW执行串行回送测试
PHP implementation of iframe cross site text replacement / iframe website text replacement
IGBT and third generation semiconductor SiC double pulse test scheme
[untitled]
IGBT与三代半导体SiC双脉冲测试方案
Dark horse headlines - Tencent's salary system reform has caused controversy; Intel expanded the recruitment of female engineers nationwide; Black horse is 100% employed really
Interview questions - written examination
【Pygame合集】回忆杀-“童年游戏”,看看你中几枪?(附五款源码自取)
Create millisecond time id in LabVIEW
LabVIEW uses the visa read function to read USB interrupt data
【Pygame小游戏】Chrome上的小恐龙竟可以用代码玩儿了?它看起来很好玩儿的样子~
