使用python实现男神女神颜值打分系统(推荐)
作者:Keegan-扬 发布时间:2021-07-17 23:06:57
标签:python,打分,系统
先给大家展示效果图,感觉不错,请参考实现代码。
具体代码如下所示:
#!/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 = '15768642'
API_KEY = 'xhiiGmGPRCRj10XIqVlVeCky'
SECRET_KEY = 'ZDMMAO7StwTKzW8BspVQxvoGtdgSW4yI'
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()
总结
以上所述是小编给大家介绍的使用python实现男神女神颜值打分系统,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://blog.csdn.net/YJG7D314/article/details/102806244


猜你喜欢
- 本文实例讲述了php字符串截取函数mb_substr用法。分享给大家供大家参考,具体如下:string mb_substr ( string
- PyCharm 是一款功能强大的 Python 编辑器,具有跨平台性,鉴于目前最新版 PyCharm 使用教程较少,为了节约时间,来介绍下p
- 1、将下载好的mysql压缩包解压到安装目录下2、新建文件 my.ini,放置到mysql安装目录下,内容如下:[mysql]# 设置mys
- 总的来说,提高应用程序性能的最好的方法是发现应用的瓶径之所在,和数据库进行交互的性能无疑是决定应用程序性能的重要环节之一。因为ADO是当前最
- 自从python2.2提供了yield关键字之后,python的生成器的很大一部分用途就是可以用来构建协同程序,能够将函数挂起返回中间值并能
- 首先给大家介绍ThinkPHP函数详解:M方法M方法用于实例化一个基础模型类,和D方法的区别在于:1、不需要自定义模型类,减少IO加载,性能
- 凡事预则立,不预则废,训练机器学习模型也是如此。数据清洗和预处理是模型训练之前的必要过程,否则模型可能就废了。本文是一个初学者指南,将带你领
- 工作时同事间几mb小文件的传输,一般使用QQ或者微信就足够了,但当传输文件几百MB或者几十G时,这种方法的效率就显得不足了。本篇就是简单说明
- <? $dbh = @mysql_connect("localhost:3306","root"
- golang修改结构体中的切片值,直接传结构体地址就可以package mainimport "fmt"type rsp
- tkinter禁用(只读)下拉列表Comboboxtkinter将下拉列表框Combobox控件的状态设置为只读,也就是不可编辑状态:# 定
- 当鼠标移动上去后,字慢慢的变大的 效果应该 如果实现啊<!DOCTYPE html PUBLIC "-//W3C//DTD
- 本篇已得到原作者Steve Dennis的翻译准予,在此Jorux表示感谢!本教程主要参考Creating a CSS Layo
- 前言字符集是一套符号和编码的规则,不论是在oracle数据库还是在mysql数据库,都存在字符集的选择问题,而且如果在数据库创建阶段没有正确
- 1、使用empty方法创建数组该方式可以创建一个空数组,dtype可以指定随机数的类型,否则随机采用一种类型生成随机数。import num
- 1 计算属性实现模糊查询vue 中通过计算属性实现模糊查询,创建 html 文件,代码直接放入即可。这里自己导入 vue,我是导入本地已经下
- 本文介绍了vue下history模式刷新后404错误解决方法,分享给大家,具体如下:官方说明文档:https://router.vuejs.
- 成品效果 <body> <div id="game" style="p
- 1、二进制数、八进制数、十六进制数转十进制数 有一个公式:二进制数、八进制数、十六进制数的各位数字分别乖以各自的基数的(N-1)次方,其和相
- 很早很早的时候,computer这个东西习惯于被称之为计算机,因为它的主要功能是完成一些科学计算的东西,我记得自己鼓捣它的时候,就是计算,根