当前位置:网站首页>【颜值检测神器】来,请拿出你们的绝活(这颜值,对得起观众么?)
【颜值检测神器】来,请拿出你们的绝活(这颜值,对得起观众么?)
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'颜值得分仅供参考,请勿当真,认为我的代码有问题的可以自行下载图片和代码进行尝试。苦笑!
总结
颜值得分仅供参考,请勿当真

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

注小编获取更多精彩内容!记得点击传送门哈
记得三连哦! 如需打包好的源码+素材免费分享滴!!传送门
边栏推荐
- 30 | 怎么重设消费者组位移?
- It is said that the verification code is a barrier in the crawler. I can break through it with only five lines of code.
- ILRuntime热更框架 安装以及断点调试
- Im instant messaging source code with tutorial /uniapp instant messaging source code, with installation tutorial
- 插入排序
- What Fiddler does for testing
- 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:
- Vs tomato assistant add header comments and usage
- csdn每日一练——找出最接近元素并输出下标
- BGP - route map extension (explanation + configuration)
猜你喜欢

LeetCode+ 21 - 25

LabVIEW执行串行回送测试

Perfect decoding purecodec 20220601
![[paper sharing] pata: fuzzing with path aware Taint Analysis](/img/f6/627344c5da588afcf70302ef29d134.png)
[paper sharing] pata: fuzzing with path aware Taint Analysis

Hyperleger fabric installation

【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)

示波器和频谱分析仪的区别

Im instant messaging source code with tutorial /uniapp instant messaging source code, with installation tutorial

IGBT and third generation semiconductor SiC double pulse test scheme

LabVIEW错误“内存已满 - 应用程序停止在节点”
随机推荐
[untitled]
细数十大信息安全原则
vtk.js中vtp下载
LabVIEW和VDM提取色彩和生成灰度图像
VS 番茄助手添加头注释 以及使用方式
A simple understanding of B tree
【Pygame小游戏】趣味益智游戏 :打地鼠,看一下能打多少只呢?(附源码)
Perfect decoding purecodec 20220601
【Pygame小遊戲】別找了,休閑遊戲專題來了丨泡泡龍小程序——休閑遊戲研發推薦
LabVIEW调用DLL时出现异常0xc0000005代码
MySQL学习之子查询
OSS stores and exports related content
Is it safe for changtou school to open an account? Is it reliable?
Fiddler filtering sessions
What Fiddler does for testing
PHP implementation of iframe cross site text replacement / iframe website text replacement
How to handle the database query error with Emoji expression in Typecho- Xingze V Club
Flowable process deployment
【LaTex】latex VS Code snippets(代码片段)
Binary tree pruning
