使用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
![](https://www.aspxhome.com/images/zang.png)
![](https://www.aspxhome.com/images/jiucuo.png)
猜你喜欢
- 我就废话不多说了,直接上代码吧!import Imagefrom datetime import datetimeimport osstr
- WaitGroup的用途:它能够一直等到所有的goroutine执行完成,并且阻塞主线程的执行,直到所有的goroutine执行完成。官方对
- 用selenium做自动化,有时候会遇到需要模拟鼠标操作才能进行的情况,比如单击、双击、点击鼠标右键、拖拽等等。而selenium给我们提供
- 代码如下:using System; using System.Data; using System.Configuration
- 文本框 textarea 限制输入文字个数的的javascript代码,我们经常在评论留言页面我们需要在客户端限制访客的留言长度,当然最好我
- 简单介绍下功能吧:使用了ASP的一个对象ServerVariables(服务器环境变量),通过这个环境变量可以获取到真正的下载地址再通过一些
- preface:做着最近的任务,对数据处理,做些简单的提特征,用机器学习算法跑下程序得出结果,看看哪些特征的组合较好,这一系列流程必然要用到
- 阅读上一篇:W3C优质网页小贴士(二) 注意字体大小网页设计者中有这么一种倾向:他们认为小字体能让网页看起来更漂亮,并能提供更多空间给每个网
- 本文实例为大家分享了js选项卡切换效果的具体实现代码,供大家参考,具体内容如下<!DOCTYPE html><html&g
- ASP,一种最先广泛的流行在WEB行业的编程语言。严格的说,ASP还算不上的编程语言。不过,因为微软的大力支持,ASP这一路,走得非常顺利。
- 直接看代码: 代码如下:Class GoogleTranslator sub Class_Initialize
- PyHook是一个基于Python的“钩子”库,主要用于监听当前电脑上鼠标和键盘的事件。这个库依赖于另一个Python库PyWin32,如同
- 前言在讲解如何解决migrate报错原因前,我们先要了解migrate做了什么事情,migrate:将新生成的迁移脚本。映射到数据库中。创建
- 我就废话不多说了,大家还是直接看代码吧~import kerasimport numpy as npimport matplotlib.py
- 最近写了两个管理后台的前端页面,其中有一个管理后台,左侧菜单导航和右侧内容页是两个iframe,需求是,点击上面的主导航时,左侧iframe
- 一、匿名块和命名块◆PL/SQL块分为良好总:命名块和匿名块。◆匿名块:以declare或begin开始,每次执行匿名块都要通过客户端工具将
- 本文实例为大家分享了Jsp+Servlet实现简单登录注册查询的具体代码,供大家参考,具体内容如下1、注册功能:制作一个注册页面用户输入:用
- 使用RS232串口线或者是RS232转USB的这一类的接口,会需要com口作为接口来进行输入输出调式,写了个脚本来控制COM口,用到了Pyt
- 今天遇到一个需要用javascript将url中的某些参数替换的需求,想起了不久前从网上淘到了一个parseUrl函数,正好可以借此实现,代
- 很多人觉得程序猿是高薪的代表,很多人都想学习一门编程语言,如果你想选择一种语言来入门编程,那么Python绝对是首选!其非常接近自然语言,精