-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamination .py
More file actions
128 lines (110 loc) · 3.76 KB
/
examination .py
File metadata and controls
128 lines (110 loc) · 3.76 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
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
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)
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 = 'door3_in' # 검숲 파일폴더명
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)
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()