CSIC_716_20191029【人脸打分系统】
今日内容:
1.调用百度的AI接口,完成人脸图像打分( 敷衍)
2.完成系统内置时间的打印
3.将上述两段代码生成可执行文件
-----------------------------------------------------------------------------------------------------------------------------
1、本人代码,提取分数性别和年龄
from aip import AipFace
import base64 """ 你的 APPID AK SK """
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
options = {'face_field': 'age,gender,beauty'}
client = AipFace(APP_ID, API_KEY, SECRET_KEY) def set_image(file):
with open(file, 'rb') as f:
res = base64.b64encode(f.read())
return res.decode('utf-8') image = set_image('123.jpg')
imageType = "BASE64" # print(image)
def face_score(file):
result = client.detect(file, imageType, options)
age=result['result'][ 'face_list'][0]['age']
gender=result['result'][ 'face_list'][0]['gender']['type']
beauty=result['result'][ 'face_list'][0]['beauty']
print(age,gender,beauty)
return age,gender,beauty face_score(image)
---------------------------------------------------------------------------------
老师写的代码,可生成小程序
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
pip install pillow
pip install baidu-aip
pip install tkinter
"""
import PIL
import time
import base64
import tkinter as tk
from PIL import Image
from PIL import ImageTk
from aip import AipFace
from tkinter.filedialog import askopenfilename # 配置百度aip参数
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
a_face = AipFace(APP_ID, API_KEY, SECRET_KEY)
image_type = 'BASE64' options = {'face_field': 'age,gender,beauty'} def get_file_content(file_path):
"""获取文件内容"""
with open(file_path, 'rb') as fr:
content = base64.b64encode(fr.read()) return content.decode('utf8') def face_score(file_path):
"""脸部识别分数"""
result = a_face.detect(get_file_content(file_path), image_type, options)
print(result)
age = result['result']['face_list'][0]['age']
beauty = result['result']['face_list'][0]['beauty']
gender = result['result']['face_list'][0]['gender']['type'] return age, beauty, gender class ScoreSystem():
"""打分系统类"""
root = tk.Tk() # 修改程序框的大小
root.geometry('800x500') # 添加程序框标题
root.title('女神颜值打分系统') # 修改背景色
canvas = tk.Canvas(root,
width=800, # 指定Canvas组件的宽度
height=500, # 指定Canvas组件的高度
bg='#E6E6FA') # 指定Canvas组件的背景色
canvas.pack() def start_interface(self):
"""主运行函数"""
self.title()
self.time_component() # 打开本地文件
tk.Button(self.root, text='打开文件', command=self.show_original_pic).place(x=50, y=150)
# 进行颜值评分
tk.Button(self.root, text='运行程序', command=self.open_files2).place(x=50, y=230)
# 显示帮助文档
tk.Button(self.root, text='帮助文档', command=self.show_help).place(x=50, y=310)
# 退出系统
tk.Button(self.root, text='退出软件', command=self.quit).place(x=50, y=390)
# 显示图框标题
tk.Label(self.root, text='原图', font=10).place(x=380, y=120)
# 修改图片大小
self.label_img_original = tk.Label(self.root)
# 设置显示图框背景
self.cv_orinial = tk.Canvas(self.root, bg='white', width=270, height=270)
# 设置显示图框边框
self.cv_orinial.create_rectangle(8, 8, 260, 260, width=1, outline='red')
# 设置位置
self.cv_orinial.place(x=265, y=150)
# 显示图片位置
self.label_img_original.place(x=265, y=150) # 设置评分标签
tk.Label(self.root, text='性别', font=10).place(x=680, y=150)
self.text1 = tk.Text(self.root, width=10, height=2)
tk.Label(self.root, text='年龄', font=10).place(x=680, y=250)
self.text2 = tk.Text(self.root, width=10, height=2)
tk.Label(self.root, text='评分', font=10).place(x=680, y=350)
self.text3 = tk.Text(self.root, width=10, height=2) # 填装文字
self.text1.place(x=680, y=175)
self.text2.place(x=680, y=285)
self.text3.place(x=680, y=385) # 开启循环
self.root.mainloop() def show_original_pic(self):
"""放入文件"""
self.path_ = askopenfilename(title='选择文件')
# 处理文件
img = Image.open(fr'{self.path_}')
img = img.resize((270, 270), PIL.Image.ANTIALIAS) # 调整图片大小至270*270
# 生成tkinter图片对象
img_png_original = ImageTk.PhotoImage(img)
# 设置图片对象
self.label_img_original.config(image=img_png_original)
self.label_img_original.image = img_png_original
self.cv_orinial.create_image(5, 5, anchor='nw', image=img_png_original) def open_files2(self):
# 获取百度API接口获得的年龄、分数、性别
age, score, gender = face_score(self.path_) # 清楚text文本框内容并进行插入
self.text1.delete(1.0, tk.END)
self.text1.tag_config('red', foreground='RED')
self.text1.insert(tk.END, gender, 'red') self.text2.delete(1.0, tk.END)
self.text2.tag_config('red', foreground='RED')
self.text2.insert(tk.END, age, 'red') self.text3.delete(1.0, tk.END)
self.text3.tag_config('red', foreground='RED')
self.text3.insert(tk.END, score, 'red') def show_help(self):
"""显示帮助"""
pass def quit(self):
"""退出"""
self.root.quit() def get_time(self, lb):
"""获取时间"""
time_str = time.strftime("%Y-%m-%d %H:%M:%S") # 获取当前的时间并转化为字符串
lb.configure(text=time_str) # 重新设置标签文本
self.root.after(1000, self.get_time, lb) # 每隔1s调用函数 get_time自身获取时间 def time_component(self):
"""时间组件"""
lb = tk.Label(self.root, text='', fg='blue', font=("黑体", 15))
lb.place(relx=0.75, rely=0.90)
self.get_time(lb) def title(self):
"""标题设计"""
lb = tk.Label(self.root, text='女神颜值打分系统',
bg='#6495ED',
fg='lightpink', font=('华文新魏', 32),
width=20,
height=2,
# relief=tk.SUNKEN
)
lb.place(x=200, y=10) score_system = ScoreSystem()
score_system.start_interface()
-----------------------------------------------------------------------------------------------------------------------------
2、上课是顺时针的例子,本人实现逆时针输出
import turtle
import time
t = turtle.Pen()
t.shape("turtle")
t.speed(0) def routeTrue( ):
t.forward(5)
t.down( )
t.forward(35)
t.left(90)
t.up( ) def routeFalse( ):
t.forward(40)
t.left(90) def numInput(i):
routeTrue() if i in [2,3,4,5,6,8,9] else routeFalse()
routeTrue() if i in [0,2,6,8] else routeFalse()
routeTrue() if i in [0,2,3,5,6,8,9] else routeFalse()
routeTrue() if i in [0,1,3,4,5,6,7,8,9] else routeFalse()
t.right(90)
routeTrue() if i in [0,1,2,3,4,7,8,9] else routeFalse()
routeTrue() if i in [0,2,3,5,6,7,8,9] else routeFalse()
routeTrue() if i in [0,4,5,6,8,9] else routeFalse()
t.right(180)
t.backward(90) def change( ):
t.backward(90)
# t.right(180)
def charac():
t.forward(40)
def getnum(date):
for i in date:
if i == '-':
charac()
t.write('年',font=("Arial", 40, "normal"))
t.pencolor('green')
change()
elif i == '/':
charac()
t.write('月', font=("Arial", 40, "normal"))
t.pencolor('blue')
change()
elif i == '+':
charac()
t.write('日', font=("Arial", 40, "normal"))
change()
else:
numInput(eval(i))
def main():
t.pencolor('black')
t.pensize(3)
t.up()
t.right(180)
t.fd(250)
Nowdate = time.strftime('%Y-%m/%d+', time.gmtime())
getnum(Nowdate)
t.hideturtle()
main( )
turtle.done()
------------------------------------------------------------------------------------------------------------------------------
3、生成可执行文件,需要安装 pyinstaller包
安装完pyinstaller包之后,进入.py文件所在文件夹,cmd中测试pyinstaller --version 是否能显示版本信息,以测试是否可用
输入命令如下:
C:\Users\xxxx\PycharmProjects\date20191029>pyinstaller -F -w 文件名.py
-F 代表生成一个文件夹,-w代表不显示控制台
CSIC_716_20191029【人脸打分系统】的更多相关文章
- java 开发 face++ 人脸特征识别系统
首先要在 face++ 注册一个账号,并且创建一个应用,拿到 api key 和 api secret: 下载 java 接入工具,一个 jar 包:https://github.com/FacePl ...
- Nodejs开发人脸识别系统-教你实现高大上的人工智能
Nodejs开发人脸识别系统-教你实现高大上的人工智能 一.缘起缘生 前段时间有个H5很火,上传个头像就可以显示自己穿军装的样子,无意中看到了一篇帖子叫 全民刷军装背后的AI技术及简单实现 ,里面 ...
- 基于深度学习的人脸识别系统(Caffe+OpenCV+Dlib)【一】如何配置caffe属性表
前言 基于深度学习的人脸识别系统,一共用到了5个开源库:OpenCV(计算机视觉库).Caffe(深度学习库).Dlib(机器学习库).libfacedetection(人脸检测库).cudnn(gp ...
- 基于深度学习的人脸识别系统(Caffe+OpenCV+Dlib)【三】VGG网络进行特征提取
前言 基于深度学习的人脸识别系统,一共用到了5个开源库:OpenCV(计算机视觉库).Caffe(深度学习库).Dlib(机器学习库).libfacedetection(人脸检测库).cudnn(gp ...
- 基于深度学习的人脸识别系统(Caffe+OpenCV+Dlib)【二】人脸预处理
前言 基于深度学习的人脸识别系统,一共用到了5个开源库:OpenCV(计算机视觉库).Caffe(深度学习库).Dlib(机器学习库).libfacedetection(人脸检测库).cudnn(gp ...
- 基于深度学习的人脸识别系统系列(Caffe+OpenCV+Dlib)——【四】使用CUBLAS加速计算人脸向量的余弦距离
前言 基于深度学习的人脸识别系统,一共用到了5个开源库:OpenCV(计算机视觉库).Caffe(深度学习库).Dlib(机器学习库).libfacedetection(人脸检测库).cudnn(gp ...
- facenet 人脸识别(二)——创建人脸库搭建人脸识别系统
搭建人脸库 选择的方式是从百度下载明星照片 照片下载,downloadImageByBaidu.py # coding=utf-8 """ 爬取百度图片的高清原图 &qu ...
- 人脸识别系统 —— 基于python的人工智能识别核心
起因 自打用python+django写了一个点菜系统,就一直沉迷python编程.正好前几天公司boss要我研究一下人脸识别,于是我先用python编写了一个人脸识别系统的核心,用于之后的整个系统. ...
- C++ 人脸识别系统的浅理解
机器学习 机器学习的目的是把数据转换成信息. 机器学习通过从数据里提取规则或模式来把数据转成信息. 人脸识别 人脸识别通过级联分类器对特征的分级筛选来确定是否是人脸. 每个节点的正确识别率很高,但正确 ...
随机推荐
- 2.4 Nginx服务器基础配置指令
2.4.1 nginx.conf文件的结构 2.4.2配置运行Nginx服务器用户(组) 2.4.3配置允许生成的worker process数 2.4.4 配置Nginx进程PID存放路径 2.4. ...
- 商城sku的选择功能--客户端
前段时间,刚好做到了有关sku这个功能.客户端的sku,和后台管理系统的sku.当初查了大量资料,遂做个记录,以免忘记. 这篇先写客户端的sku功能把,类似于去淘宝京东等购物,就会有个规格让你选择.如 ...
- HTML5 Shiv--解决IE(IE6/IE7/IE8)不兼容HTML5标签的方法
HTML5的语义化标签以及属性,可以让开发者非常方便地实现清晰的web页面布局.大多数浏览器基本兼容html5,但目前来说ie6/ie7/ie8还不兼容html5标签,所以需要javascript处理 ...
- json传参报错
restful接口报错: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('e' (code 101)): w ...
- python--面向对象:封装
广义上面向对象的封装 :代码的保护,面向对象的思想本身就是一种只让自己的对象能调用自己类中的方法 狭义上的封装 ——> 面向对象的三大特性之一属性 和 方法都藏起来 不让你看见 "&q ...
- mysql数据库 --数据类型、约束条件
今日内容 表的详细使用 1.创建表的完成语法 2.字段类型 整型.浮点型.字符类型.日期类型.枚举与集合类型 3.约束条件 primary key.unique.not null.default 一. ...
- 笔记51 Mybatis快速入门(二)
Mybatis的CRUD 1.修改配置文件Category.xml,提供CRUD对应的sql语句. <?xml version="1.0" encoding="UT ...
- 原生js如何获取某一元素的高度
三种方法: 1.document.getElementById("id").style.height,这种方法的前提是必须之前已经显示的在css中声明过height,才能取得正确的 ...
- 单源最短路径问题1 (Bellman-Ford算法)
/*单源最短路径问题1 (Bellman-Ford算法)样例: 5 7 0 1 3 0 3 7 1 2 4 1 3 2 2 3 5 2 4 6 3 4 4 输出: [0, 3, 7, 5, 9] */ ...
- zjoi 2008 树的统计——树链剖分
比较基础的一道树链剖分的题 大概还是得说说思路 树链剖分是将树剖成很多条链,比较常见的剖法是按儿子的size来剖分,剖分完后对于这课树的询问用线段树维护——比如求路径和的话——随着他们各自的链向上走, ...