百度AI动植物识别tkinter窗口

#分别建立测试项1和测试项2文件

#测试项1

from tkinter import *
from PIL import Image, ImageTk
import 测试2


class main:
def __init__(self, window):
self.window = window
self.window.title("AI识别系统")
self.window.geometry("500x500")
self.lab = Label(master=self.window)
self.img = Image.open('向日葵1.jpg')
self.img = self.img.resize((500, 200))
self.img_TK = ImageTk.PhotoImage(self.img)
self.lab.config(image=self.img_TK)
self.lab.pack()
self.button1 = Button(self.window, text='1.动物识别', command=self.change1, height=5, width=20)
self.button1.pack()
self.button1.place(x=60, y=230)

self.button2 = Button(self.window, text='2.植物识别', command=self.change2, height=5, width=20)
self.button2.pack()
self.button2.place(x=60, y=350)

self.button3 = Button(self.window, text='3.货币识别', command=self.change3, height=5, width=20)
self.button3.pack()
self.button3.place(x=280, y=230)

self.button4 = Button(self.window, text='4.品牌Logo识别', command=self.change4, height=5, width=20)
self.button4.pack()
self.button4.place(x=280, y=350)

def destory(self):
self.lab.destroy()
self.button1.destroy()
self.button2.destroy()
self.button3.destroy()
self.button4.destroy()

def change1(self):
self.destory()
测试2.animal(self.window)

def change2(self):
self.destory()
测试2.plant(self.window)

def change3(self):
self.destory()
测试2.currency(self.window)

def change4(self):
self.destory()
测试2.Logo(self.window)


if __name__ == '__main__':
root = Tk()
p1 = main(root)
root.mainloop()

#测试项2

from tkinter import *
from PIL import Image, ImageTk
from aip import AipImageClassify
from tkinter.filedialog import askopenfilename
import 测试1

APP_ID = '33273196'
API_ID = 'WzRVQ8YbXYvUp0FiKLel3ZEy'
SECRET_KEY = 'upRALZvh9WzoVnaEW8MiOeGi9BRevt84'
client = AipImageClassify(APP_ID, API_ID, SECRET_KEY)
options = {}
options['top_num'] = 2
options['baike_num'] = 2


class animal:
def __init__(self, window):
self.window = window
self.window.title("动物识别")
self.window.geometry("600x500")

self.button1 = Button(self.window, text='选择图片', command=self.choosepic, width=80)
self.button1.pack()

self.button2 = Button(self.window, text='返回', command=self.back, width=80)
self.button2.pack()

self.lab1 = Label(master=self.window)
self.lab1.pack()
self.lab2 = Label(master=self.window, wraplength=450, justify='left')
self.lab2.pack()

def getInfor(self, file_path):
with open(file_path, 'rb') as file:
image = file.read()
result = client.animalDetect(image, options)
return result

def choosepic(self):
path = askopenfilename(title='选择文件图片')
img_pil = Image.open(path)
resized_img = img_pil.resize((300, 250))
img_tk = ImageTk.PhotoImage(resized_img)
self.lab1.configure(image=img_tk)
self.lab1.image = img_tk

result = self.getInfor(path)

name = result.get('result')[0].get('name')
score = result.get('result')[0].get('score')
description = result.get('result')[0].get('baike_info').get('description')

infor = f'动物名称:{name}, 置信度:{score} \n百科信息:{description}'

self.lab2.configure(text=infor)

def back(self):
self.button1.destroy()
self.button2.destroy()
self.lab1.destroy()
self.lab2.destroy()
测试1.main(self.window)


class plant(animal):
def __init__(self, window):
super().__init__(window)
self.window.title("植物识别")

def getInfor(self, file_path):
with open(file_path, 'rb') as file:
image = file.read()
result = client.plantDetect(image, options)
return result

def choosepic(self):
path = askopenfilename(title='选择文件图片')
img_pil = Image.open(path)
resized_img = img_pil.resize((300, 250))
img_tk = ImageTk.PhotoImage(resized_img)
self.lab1.configure(image=img_tk)
self.lab1.image = img_tk

result = self.getInfor(path)

name = result.get('result')[0].get('name')
score = result.get('result')[0].get('score')
description = result.get('result')[0].get('baike_info').get('description')

infor = f'植物:{name}, 置信度:{score} \n百科信息:{description}'

self.lab2.configure(text=infor)


class currency(animal):
def __init__(self, window):
super().__init__(window)
self.window.title("货币识别")

def getInfor(self, file_path):
with open(file_path, 'rb') as file:
image = file.read()
result = client.currency(image, options)
return result

def choosepic(self):
path = askopenfilename(title='选择文件图片')
img_pil = Image.open(path)
resized_img = img_pil.resize((300, 250))
img_tk = ImageTk.PhotoImage(resized_img)
self.lab1.configure(image=img_tk)
self.lab1.image = img_tk

result = self.getInfor(path)

currencyName = result.get('result').get('currencyName')
currencyCode = result.get('result').get('currencyCode')
currencyDenomination = result.get('result').get('currencyDenomination')
year = result.get('result').get('year')

infor = f'货币名称:{currencyName}, 货币代码:{currencyCode} \n 货币面值:{currencyDenomination}, 年份:{year}'

self.lab2.configure(text=infor)


class Logo(animal):
def __init__(self, window):
super().__init__(window)
self.window.title("Logo识别")

def getInfor(self, file_path):
with open(file_path, 'rb') as file:
image = file.read()
result = client.logoSearch(image, options)
return result

def choosepic(self):
path = askopenfilename(title='选择文件图片')
img_pil = Image.open(path)
resized_img = img_pil.resize((300, 250))
img_tk = ImageTk.PhotoImage(resized_img)
self.lab1.configure(image=img_tk)
self.lab1.image = img_tk

result = self.getInfor(path)

name = result.get('result')[0].get('name')
probability = result.get('result')[0].get('probability')
infor = f'loge名称:{name}\n可置信度:{probability}'

self.lab2.configure(text=infor)

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值