python實現(xiàn)圖片自動分類小程序
更新時間:2025年05月22日 10:03:18 作者:水木姚姚
這篇文章主要為大家詳細介紹了如何使用python實現(xiàn)圖片自動分類小程序,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
用 python 編寫了一個圖片自動分類的小程序,先編了一部分功能:小程序界面。
操作系統(tǒng)平臺:Microsoft Windows 8.1
編程語言:python
一、圖片自動分類小程序效果圖
尚沒有進行圖片分類小程序效果圖。

圖一
點擊圖一中選擇圖片按鈕,在圖二中選擇一張圖片

圖二
選擇圖片后的顯示效果

圖三
圖片自動分類功能下一篇再寫。
二、部分源代碼
目前程序部分源代碼:
1.引用的python模塊
import cv2 import numpy as np import sys import os import tkinter import PIL from PIL import Image,ImageTk from tkinter import ttk from tkinter.messagebox import showinfo
2.選擇圖片代碼
global canvas
global pre_img1
def position_picture(f):
img=PIL.Image.open(f)
img=img.resize((150,150))
preview_img=ImageTk.PhotoImage(img)
return preview_img
def selected_picture():
global canvas,pre_img1
d=tkinter.filedialog.askopenfilename(title='picture',filetypes=[('jpg','*.jpg')])
pre_img1=position_picture(d)
canvas.delete('all')
canvas.create_image((75,75),image=pre_img1) 3.程序界面部分代碼
if __name__=='__main__':
global canvas
global pre_img1
root=tkinter.Tk()
root.title("預(yù)覽")
pre_img=position_picture(fn)
canvas=tkinter.Canvas(root,width=150,height=150,bg='white')
canvas.grid(column=2,row=0)
canvas.create_image((75,75),image=pre_img)
for i in range(0,5):
canvas1=tkinter.Canvas(root,width=150,height=150,bg='white')
canvas1.grid(column=i,row=4)
canvas1.create_image((75,75),image=pre_img)
......
button1=ttk.Button(root,text="選擇圖片",command=selected_picture)
button1.grid(column=2,row=2)
button2=ttk.Button(root,text="自動分類",command=identify_picture)
button2.grid(column=2,row=3)
root.mainloop 到此這篇關(guān)于python實現(xiàn)圖片自動分類小程序的文章就介紹到這了,更多相關(guān)python圖片分類內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python基于pycrypto實現(xiàn)的AES加密和解密算法示例
這篇文章主要介紹了Python基于pycrypto實現(xiàn)的AES加密和解密算法,結(jié)合實例形式分析了Python使用pycrypto模塊進行AES加密與解密操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2018-04-04
python實現(xiàn)掃描日志關(guān)鍵字的示例
下面小編就為大家分享一篇python實現(xiàn)掃描日志關(guān)鍵字的示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-04-04

