最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用python實(shí)現(xiàn)男神女神顏值打分系統(tǒng)(推薦)

 更新時(shí)間:2019年10月31日 10:37:17   作者:Keegan-揚(yáng)  
這篇文章主要介紹了用python做一個(gè)男神女神顏值打分系統(tǒng)(程序分析見注釋),需要的朋友可以參考下

先給大家展示效果圖,感覺不錯(cuò),請(qǐng)參考實(shí)現(xiàn)代碼。


在這里插入圖片描述

具體代碼如下所示:

#!/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參數(shù)
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):
  """獲取文件內(nèi)容"""
  with open(file_path, 'rb') as fr:
    content = base64.b64encode(fr.read())
    return content.decode('utf8')
def face_score(file_path):
  """臉部識(shí)別分?jǐn)?shù)"""
  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():
  """打分系統(tǒng)類"""
  root = tk.Tk()
  # 修改程序框的大小
  root.geometry('800x500')
  # 添加程序框標(biāo)題
  root.title('女神/男神顏值打分系統(tǒng)')
  # 修改背景色
  canvas = tk.Canvas(root,
            width=800, # 指定Canvas組件的寬度
            height=500, # 指定Canvas組件的高度
            bg='#E6E6FA') # 指定Canvas組件的背景色
  canvas.pack()
  def start_interface(self):
    """主運(yùn)行函數(shù)"""
    self.title()
    self.time_component()
    # 打開本地文件
    tk.Button(self.root, text='打開文件', command=self.show_original_pic).place(x=50, y=150)
    # 進(jìn)行顏值評(píng)分
    tk.Button(self.root, text='運(yùn)行程序', command=self.open_files2).place(x=50, y=230)
    # 顯示幫助文檔
    tk.Button(self.root, text='幫助文檔', command=self.show_help).place(x=50, y=310)
    # 退出系統(tǒng)
    tk.Button(self.root, text='退出軟件', command=self.quit).place(x=50, y=390)
    # 顯示圖框標(biāo)題
    tk.Label(self.root, text='原圖', font=10).place(x=380, y=120)
    # 修改圖片大小
    self.label_img_original = tk.Label(self.root)
    # 設(shè)置顯示圖框背景
    self.cv_orinial = tk.Canvas(self.root, bg='white', width=270, height=270)
    # 設(shè)置顯示圖框邊框
    self.cv_orinial.create_rectangle(8, 8, 260, 260, width=1, outline='red')
    # 設(shè)置位置
    self.cv_orinial.place(x=265, y=150)
    # 顯示圖片位置
    self.label_img_original.place(x=265, y=150)
    # 設(shè)置評(píng)分標(biāo)簽
    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='評(píng)分', 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)
    # 開啟循環(huán)
    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) # 調(diào)整圖片大小至270*270
    # 生成tkinter圖片對(duì)象
    img_png_original = ImageTk.PhotoImage(img)
    # 設(shè)置圖片對(duì)象
    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接口獲得的年齡、分?jǐn)?shù)、性別
    age, score, gender = face_score(self.path_)
    # 清楚text文本框內(nèi)容并進(jìn)行插入
    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):
    """獲取時(shí)間"""
    time_str = time.strftime("%Y-%m-%d %H:%M:%S") # 獲取當(dāng)前的時(shí)間并轉(zhuǎn)化為字符串
    lb.configure(text=time_str) # 重新設(shè)置標(biāo)簽文本
    self.root.after(1000, self.get_time, lb) # 每隔1s調(diào)用函數(shù) get_time自身獲取時(shí)間
  def time_component(self):
    """時(shí)間組件"""
    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):
    """標(biāo)題設(shè)計(jì)"""
    lb = tk.Label(self.root, text='女神/男神顏值打分系統(tǒng)',
           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()

總結(jié)

以上所述是小編給大家介紹的使用python實(shí)現(xiàn)男神女神顏值打分系統(tǒng),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • Opencv常見圖像格式Data Type及代碼實(shí)例

    Opencv常見圖像格式Data Type及代碼實(shí)例

    這篇文章主要介紹了Opencv常見圖像格式Data Type及代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11
  • 簡(jiǎn)單的python后臺(tái)管理程序

    簡(jiǎn)單的python后臺(tái)管理程序

    這篇文章主要為大家詳細(xì)介紹了簡(jiǎn)單python后臺(tái)管理程序的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Python使用Selenium爬取淘寶異步加載的數(shù)據(jù)方法

    Python使用Selenium爬取淘寶異步加載的數(shù)據(jù)方法

    今天小編就為大家分享一篇Python使用Selenium爬取淘寶異步加載的數(shù)據(jù)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • python list 查詢是否存在并且并返回下標(biāo)的操作

    python list 查詢是否存在并且并返回下標(biāo)的操作

    這篇文章主要介紹了python list 查詢是否存在并且并返回下標(biāo)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • 基于Python實(shí)現(xiàn)天天酷跑功能

    基于Python實(shí)現(xiàn)天天酷跑功能

    這篇文章主要介紹了基于Python實(shí)現(xiàn)天天酷跑功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01
  • 基于python制作簡(jiǎn)易版學(xué)生信息管理系統(tǒng)

    基于python制作簡(jiǎn)易版學(xué)生信息管理系統(tǒng)

    這篇文章主要介紹了基于python制作簡(jiǎn)易版學(xué)生信息管理系統(tǒng),文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有很好地幫助,需要的朋友可以參考下
    2021-04-04
  • Python基礎(chǔ)教程之裝飾器詳解

    Python基礎(chǔ)教程之裝飾器詳解

    眾所周知,Python裝飾器是一種常見的元編程特性,在本教程中,我們將深入探討Python裝飾器的基本概念、語法及其應(yīng)用,并利用實(shí)際例子加深理解,感興趣的小伙伴快跟隨小編一起了解一下吧
    2023-06-06
  • Anaconda中導(dǎo)出環(huán)境的實(shí)現(xiàn)步驟

    Anaconda中導(dǎo)出環(huán)境的實(shí)現(xiàn)步驟

    在 Anaconda 中導(dǎo)出環(huán)境是一種常用的做法,可以將當(dāng)前的環(huán)境配置導(dǎo)出到一個(gè)文件中,本文主要介紹了Anaconda中導(dǎo)出環(huán)境的實(shí)現(xiàn)步驟,具有一定的參考價(jià)值
    2024-05-05
  • Python使用Selenium實(shí)現(xiàn)按文本查找元素

    Python使用Selenium實(shí)現(xiàn)按文本查找元素

    本文我們將通過示例為大家詳細(xì)介紹如何在Python中使用selenium通過文本查找元素的方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以參考一下
    2023-11-11
  • pandas-resample按時(shí)間聚合實(shí)例

    pandas-resample按時(shí)間聚合實(shí)例

    今天小編就為大家分享一篇pandas-resample按時(shí)間聚合實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12

最新評(píng)論

广西| 沙坪坝区| 九寨沟县| 甘泉县| 敦化市| 大冶市| 武汉市| 南康市| 郁南县| 宜黄县| 洪泽县| 依安县| 临猗县| 天水市| 万盛区| 凌源市| 水城县| 临朐县| 望江县| 灵台县| 夏邑县| 玉树县| 盐亭县| 东光县| 长沙市| 营口市| 信阳市| 浪卡子县| 武汉市| 库车县| 洞口县| 清苑县| 蓬莱市| 安宁市| 乌什县| 兴和县| 吉水县| 兴义市| 高平市| 普兰店市| 贵南县|