-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamination_revise.py
More file actions
155 lines (130 loc) · 4.79 KB
/
examination_revise.py
File metadata and controls
155 lines (130 loc) · 4.79 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
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
154
155
import cv2
from glob import glob
import os
import matplotlib.pyplot as plt
import natsort
import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from tqdm.auto import tqdm
import matplotlib
import gc
"""
name 81 줄
target 직접입력 필요 !!!!!!!!!!!!!!!!!!! 82 줄
"""
save_count = 0
current_image_index = 0
text_handle = None
text_file_count = None
iter_count = 0
image_cache = {}
image_name = None
def wrapper(event):
save_image(event, image)
def update_image(new_data, im):
im.set_data(new_data)
fig.canvas.draw_idle()
def save_image(event, image):
global save_count
new_folder = f"inspect/{name}/{target_sheet}"
os.makedirs(new_folder, exist_ok=True)
image_path = os.path.join(new_folder, os.path.basename(file_list[current_image_index]))
if not os.path.isfile(image_path):
print(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
cv2.imwrite(image_path, image)
save_count += 1
next_image(None)
def load_image(image_path):
global text_handle, file_len, iter_count, text_file_count , image_name , save_count , bus1_boxes , colors
if image_path in image_cache:
image = image_cache[image_path]
else:
image = cv2.imread(image_path, cv2.IMREAD_COLOR)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
for index , box in enumerate(bus1_boxes):
x , y = box
cv2.rectangle(image , x,y,colors[index % len(colors)],2)
image_cache[image_path] = image
ax.cla()
ax.imshow(image, cmap='gray')
ax.axis('off')
image_name = os.path.basename(image_path)
ax.set_title(f"{os.path.basename(image_path)}")
if text_handle:
text_handle.remove()
text_file_count.remove()
file_count = (iter_count % file_len) + 1
text_handle = ax.text(0.5, 0.5, f"{save_count}", fontsize=15, ha='center', color='r')
text_file_count = ax.text(500, 0.5, f"{file_count} / {file_len}", fontsize=15, ha='center', color='b')
iter_count += 1
return image
def next_image(event):
global current_image_index, image, text_file_count
current_image_index = (current_image_index + 1) % len(file_list)
image = load_image(file_list[current_image_index])
canvas.draw_idle()
gc.collect()
def previous_image(event):
global current_image_index, image, text_file_count, iter_count
iter_count -= 2
current_image_index = (current_image_index - 1) % len(file_list)
image = load_image(file_list[current_image_index])
canvas.draw_idle()
gc.collect()
def delete_image(event):
global image_name , save_count
image_path = os.path.join('inspect' , name , str(target_sheet) , image_name)
if os.path.isfile(image_path):
print(f"Delted {image_name}")
os.remove(image_path)
save_count = len(os.listdir(os.path.join('inspect' , name , str(target_sheet))))
name = 'detect_scen1.1/_camera8_image_raw' # 검숲 파일폴더명
target_sheet = 6 # 검수 타켓 좌석
file_list = natsort.natsorted(glob(os.path.join(name, '*.jpg')))
#file_name = 'frame_1712294539.jpg'
file_name = os.path.basename(file_list[0])
try:
file_index = file_list.index(os.path.join(name, file_name))
except ValueError:
raise Exception("File not Found")
file_list = file_list[file_index:]
file_len = len(file_list)
bus1_boxes = [ # 카메라 8번 후면 좌석번호
((815 , 344) , (872 , 402)), # 1번좌석
((716 , 353) , (754 , 400)), # 2번좌석
((1147 , 346) , (1230 ,408)), # 3번좌석
((1040 , 343) , (1138 , 403)), # 4번좌석
((765 , 446) , (838 , 525)), # 5번좌석
((624 , 429) , (720 , 522)), # 6번좌석
((1175 , 472) , (1265 , 514)), # 7번좌석
((1043 ,478) , (1140 , 539)) , # 8번좌석
((615 , 527) , (754 , 653)), # 9번좌석
((504 , 658) , (720 , 801)) , # 10번좌석
((497 , 811) , (708 , 976)) , # 11번좌석
((1180 , 518) , (1343 ,686)) , # 12번좌석
((1190 , 699) , (1373 , 811)), # 13번좌석
((1192 , 817) , (1404 , 976)), # 14번좌석
]
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (0, 255, 255), (255, 0, 255), (128, 128, 0), (0, 128, 128)]
try:
save_count = len(os.listdir(os.path.join('inspect' , name , str(target_sheet))))
except:
save_count = 0
root = tk.Tk()
root.title("Image plot")
root.geometry('600x600+1000+200')
matplotlib.use('TkAgg')
plt.ioff()
fig, ax = plt.subplots(dpi=80)
image = load_image(file_list[current_image_index])
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
#root.bind('<Return>', wrapper)
root.bind('<d>',next_image)
root.bind('<a>',previous_image)
root.bind('<Right>', next_image)
root.bind('<Left>', previous_image)
root.bind('<Delete>',delete_image)
root.mainloop()