当需要手动分选大量图片集的时候,可能写一个GUI的程序效率更高。
1.首先可以通过预处理得到图片名称的list
比如在Windows下可以用
dir /s /b>list.txt生成对应的list,最好进行排序,比如可以通过notepad++打开生成的.txt文件,把一些路径的前缀去掉,ctrl+f 替换掉即可,还要删掉里面增加的.txt文件的list
然后notepad++也有排序的功能,在Edit---Line Operations---Sort Lines in Ascending Order(从小到大)
然后调用我写的GUI程序即可
2.代码:
#---FYJ--- #--GUI for classification in python3 # from tkinter import * import PIL from PIL import Image from PIL import ImageTK import tkinter as tk import os import matplotlib.pyplot as plt # 等待分类的图像名称的list root_path = 'E:/vot2019/agility/list.txt' img_list = [] for i in open(root_path,'r',encoding='UTF-8'): img_list.append('E:/vot2019/agility/'+i[:len(i)-1]) length = len(img_list) str_v1 = StringVar num = 0 def next_image(): global num,names,f_file_log f_file_log=open('E:/vot2019/agility/log.txt','w') f_file_log.write(str(num)) del names['path'+str(num)] del names['pilImage'+str(num)] del names['im_h'+str(num)] del names['im_w'+str(num)] del names['img'+str(num)] num =num+1 names['path'+str(num)] = img_list[num] names['pilImage'+str(num)] = Image.open(names['path'+str(num)]) names['im_h'+str(num)] = names['pilImage'+str(num)].size[0] names['im_w'+str(num)] = names['pilImage'+str(num)].size[1] alpha = names['im_h'+str(num)]/names['im_w'+str(num)] names['pilImage'+str(num)] = names['pilImage'+str(num)].resize((int(300*alpha),300)) names['img'+str(num)] = ImageTK.PhotoImage(names['pilImage'+str(num)]) imLabel.configure(image=names['img'+str(num)]) txLabel.configure(text='No: '+str(num)) nm_en.delete(0,END) nm_en.insert(0,img_list[num].split('/')[-1]) def pick_image00(): global f_file_00,num,names,f_file_log f_file_log=open('E:/vot2019/agility/log.txt','w') f_file_log.write(str(num)) f_file_00=open('E:/vot2019/agility/pick_00.txt','a') f_file_00.write(img_list[num]) f_file_00.write('\n') f_file_00.close() del names['path'+str(num)] del names['pilImage'+str(num)] del names['im_h'+str(num)] del names['im_w'+str(num)] del names['img'+str(num)] num =num+1 names['path'+str(num)] = img_list[num] names['pilImage'+str(num)] = Image.open(names['path'+str(num)]) names['im_h'+str(num)] = names['pilImage'+str(num)].size[0] names['im_w'+str(num)] = names['pilImage'+str(num)].size[1] alpha = names['im_h'+str(num)]/names['im_w'+str(num)] names['pilImage'+str(num)] = names['pilImage'+str(num)].resize((int(300*alpha),300)) names['img'+str(num)] = ImageTK.PhotoImage(names['pilImage'+str(num)]) imLabel.configure(image=names['img'+str(num)]) txLabel.configure(text='No: '+str(num)) nm_en.delete(0,END) nm_en.insert(0,img_list[num].split('/')[-1]) def pick_image01(): global f_file_01,num,names,f_file_log f_file_log=open('E:/vot2019/agility/log.txt','w') f_file_log.write(str(num)) f_file_01=open('E:/vot2019/agility/pick_01.txt','a') f_file_01.write(img_list[num]) f_file_01.write('\n') f_file_00.close() del names['path'+str(num)] del names['pilImage'+str(num)] del names['im_h'+str(num)] del names['im_w'+str(num)] del names['img'+str(num)] num =num+1 names['path'+str(num)] = img_list[num] names['pilImage'+str(num)] = Image.open(names['path'+str(num)]) names['im_h'+str(num)] = names['pilImage'+str(num)].size[0] names['im_w'+str(num)] = names['pilImage'+str(num)].size[1] alpha = names['im_h'+str(num)]/names['im_w'+str(num)] names['pilImage'+str(num)] = names['pilImage'+str(num)].resize((int(300*alpha),300)) names['img'+str(num)] = ImageTK.PhotoImage(names['pilImage'+str(num)]) imLabel.configure(image=names['img'+str(num)]) txLabel.configure(text='No: '+str(num)) nm_en.delete(0,END) nm_en.insert(0,img_list[num].split('/')[-1]) def pick_image02(): global f_file_00,num,names,f_file_log f_file_log=open('E:/vot2019/agility/log.txt','w') f_file_log.write(str(num)) f_file_02=open('E:/vot2019/agility/pick_00.txt','a') f_file_02.write(img_list[num]) f_file_02.write('\n') f_file_02.close() del names['path'+str(num)] del names['pilImage'+str(num)] del names['im_h'+str(num)] del names['im_w'+str(num)] del names['img'+str(num)] num =num+1 names['path'+str(num)] = img_list[num] names['pilImage'+str(num)] = Image.open(names['path'+str(num)]) names['im_h'+str(num)] = names['pilImage'+str(num)].size[0] names['im_w'+str(num)] = names['pilImage'+str(num)].size[1] alpha = names['im_h'+str(num)]/names['im_w'+str(num)] names['pilImage'+str(num)] = names['pilImage'+str(num)].resize((int(300*alpha),300)) names['img'+str(num)] = ImageTK.PhotoImage(names['pilImage'+str(num)]) imLabel.configure(image=names['img'+str(num)]) txLabel.configure(text='No: '+str(num)) nm_en.delete(0,END) nm_en.insert(0,img_list[num].split('/')[-1]) names = locals() root = tk.Tk() root.geometry('1800x1080') root.resizable(width=False,height=False) btn1 = tk.Button(root,text='Next Image',command=next_image) btn1.place(x=10,y=10,width=120,height=30) btn2 = tk.Button(root,text='0-0-0-0-0',command=pick_image00) btn2.place(x=10,y=180,width=120,height=30) btn3 = tk.Button(root,text='0-0-0-0-1',command=pick_image01) btn3.place(x=10,y=350,width=120,height=30) btn4 = tk.Button(root,text='0-0-0-0-2',command=pick_image02) btn4.place(x=10,y=520,width=120,height=30) txLabel=tk.Label(root,text='No: '+str(num)) txLabel.place(x=10,y=550,width=120,height=30) nm_en=Entry(root,textvariable=str_v1) nm_en.insert(0,img_list[num].split('/')[-1]) nm_en.place(x=10,y=580,width=120,height=30) names['path'+str(num)] = img_list[num] names['pilImage'+str(num)] = Image.open(names['path'+str(num)]) names['im_h'+str(num)] = names['pilImage'+str(num)].size[0] names['im_w'+str(num)] = names['pilImage'+str(num)].size[1] alpha = names['im_h'+str(num)]/names['im_w'+str(num)] names['pilImage'+str(num)] = names['pilImage'+str(num)].resize((int(300*alpha),300)) names['img'+str(num)] = ImageTK.PhotoImage(names['pilImage'+str(num)]) imLabel=tk.Label(root,image=names['img'+str(num)],width=800,height=350) imLabel.pack() root.mainloop()可能有些地方需要自己修改一下,注意各种路径的位置