-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimageTool.py
More file actions
84 lines (66 loc) · 2.54 KB
/
imageTool.py
File metadata and controls
84 lines (66 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from Tkinter import *
import ImageTk, cPickle, glob
from PIL import Image
class App( Frame ):
def __init__( self, parent ):
Frame.__init__( self, parent )
self.parent = parent
self.parent.grid()
self.train = dict()
self.i = 0
self.fns = glob.glob("*.png")
## start up the UI
self.initUI()
def initUI( self ):
## set the key bindings for the Enter key, and the keypad Enter key
self.parent.bind( '<Return>', self.submit_callback )
self.parent.bind( '<KP_Enter>', self.submit_callback )
## name of the program
self.parent.title( "Label Training Data" )
## open the image
image = Image.open( self.fns[ self.i ] )
photo = ImageTk.PhotoImage( image, master=self )
## put the image in a Label object
img_label = Label( self, image=photo )
img_label.image = photo
img_label.grid(row=0,columnspan=2)
## entry
ent_label = Label( self, text="Label:" )
ent_label.grid( row=1, column=0 )
self.entry = Entry( self )
self.entry.grid( row=1, column=1 )
self.entry.focus()
## submit button
submit_btn = Button( self, text="Submit" )
submit_btn.bind( '<Button-1>', self.submit_callback )
submit_btn.grid( row=2, columnspan=2 )
## quit button
quit_btn = Button( self, text="Save and Quit", command=self.quit_callback )
quit_btn.grid( row=3, columnspan=2 )
## pack it up
self.pack()
def submit_callback( self, event=None ):
## associate the user input with the filename
self.train[ self.fns[ self.i ] ] = self.entry.get()
## increment the counter
self.i += 1
## if we're at the end of the data..
if self.i == len( self.fns ):
## save/dump the data
cPickle.dump( self.train, open( "train_complete.pkl", "w" ), -1 )
## kill the aplication
self.parent.destroy()
## reload the window
self.initUI()
def quit_callback( self ):
## save/dump the data
cPickle.dump( self.train, open( "train_partial.pkl", "w" ), -1 )
## kill the aplication
self.parent.destroy()
def main():
root = Tk()
root.geometry("250x100+100+100")
app = App( root )
root.mainloop()
if __name__=="__main__":
main()