-
Notifications
You must be signed in to change notification settings - Fork 1
/
button_press.py
153 lines (128 loc) · 5.49 KB
/
button_press.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import sys
import cv2
import copy
from enum import Enum
from var import mode
# for keyboard cmds or for quiting
def key_press(event, master, imgObj):
# reject key/mouse presses while focus is on entry fields
if str(master.window.focus_get().__class__) == "Tkinter.Entry":
return
# if the 'r' key is pressed, reset the cropping region
if event.keysym == 'r':
print("points"), master.pts
master.pts=[]
if master.mode == mode.orig and master.imageModified == True:
print "Clearing regions of interests..."
imgObj.imgLive = imgObj.imgCopy.copy()
if master.mode == mode.cropped and master.imageModified == True:
print "Resetting Crop level..."
imgObj.imgLive = imgObj.imgCopy.copy()
if master.imageModified == False:
print "Could not reset. Nothing available to reset to."
master.imageModified = False
print("points after"), master.pts
# if the 'l' key is pressed, print the pt list
elif event.keysym == 'l':
print "Printing points..."
for i in range(0,len(master.pts),2):
print master.pts[i], master.pts[i+1]
# if the 'c' key is pressed, crop the images
elif event.keysym == 'c':
if len(master.pts) < 2:
print "Could not crop. No ROIs defined."
else:
print "Cropping ROIs..."
imgObj.crop_roi()
master.imageModified = True
# needed to make it show image
#cv2.waitKey(0)
# if the 'p' key is pressed, goto processed images list
elif event.keysym == 'p':
imgObj.reset()
if master.mode == mode.orig:
master.pts = []
if len(master.cropList) > 0:
print "Entering cropped image list..."
master.mode = mode.cropped
imgObj = master.update_curr_img_obj()
master.imageModified = False
master.setup_mode()
imgObj.set_entry_data()
# if the 'o' key is pressed, goto original :images list
elif event.keysym == 'o':
if master.mode == mode.cropped:
master.pts = []
if len(master.origList) > 0:
print "Entering original image list..."
master.mode = mode.orig
master.imageModified = False
master.setup_mode()
imgObj.set_entry_data()
# if the '.' key is pressed, post to the competition server
elif event.keysym == '.':
print "posting to competition server."
# if the 'n' key is pressed, goto prev image
elif event.keysym == 'n':
if master.mode == mode.cropped:
if master.cropIndex > 0:
master.cropIndex = master.cropIndex - 1
else:
if master.origIndex > 0:
master.origIndex = master.origIndex - 1
master.imageModified = False
imgObj = master.update_curr_img_obj()
if master.mode == mode.cropped:
imgObj.set_entry_data()
# if the 'm' key is pressed, goto next image
elif event.keysym == 'm':
if master.mode == mode.cropped:
if master.cropIndex < len(master.cropList) - 1:
master.cropIndex = master.cropIndex + 1
else:
if master.origIndex < len(master.origList) - 1:
master.origIndex = master.origIndex + 1
master.imageModfied = False
imgObj = master.update_curr_img_obj()
if master.mode == mode.cropped:
imgObj.set_entry_data()
# if the 'x' key is pressed, export the characteristics of a target in json
elif event.keysym == 'x':
if master.mode == mode.cropped:
imgObj = master.update_curr_img_obj()
imgObj.make_json()
# if d is pressed, it removes image from cropped image list (may need to be expanded to original list)
elif event.keysym == 'd':
if master.mode == mode.cropped:
if master.cropIndex > 0:
# if not currently on first image, delete current image and move it back one index
master.cropList.pop(master.cropIndex)
master.cropIndex = master.cropIndex - 1
elif master.cropIndex == 0 and len(master.cropList) > 1:
# if currently on first image, but more than one image in list, delete current and move to next image
master.cropList.pop(master.cropIndex)
master.cropIndex = master.cropIndex + 1
elif master.cropIndex == 0 and len(master.cropList) == 1:
# if currently on first image and only one image, delete current and go back to orig list
master.cropList.pop(master.cropIndex)
master.mode = mode.orig
imgObj = master.update_curr_img_obj()
imgObj.set_entry_data()
# if the 'a' key is pressed, gives option to open new directory to for images
elif event.keysym == 'a':
if master.mode == mode.orig:
master.import_images_alt()
# if the 'q' key is pressed, break from the loop
elif event.keysym == 'q':
print "Exiting on q-press"
sys.exit(0)
# for click-n-crop feature
def mouse_press(event, master, imgObj):
# only allow a single set of pts for cropped mode
#if mode == imageType.cropped:
# pts = []
# image = clone.copy()
master.pt0 = (event.x, event.y)
def mouse_release(event, master, imgObj):
master.pt1 = (event.x, event.y)
imgObj.make_rectangle()