-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUI_func.py
276 lines (234 loc) · 8.01 KB
/
GUI_func.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
"""
程序参数 功能函数 回调函数
"""
import tkinter as tk # 使用Tkinter_GUI包
from tkinter import filedialog, END
import tkinter_stdout as mystd
"""
程序参数配置
"""
# 格式.
format_im = ['png', 'jpeg', 'jpg', 'tiff', 'bmp']
format_vi = ['mp4', 'avi']
format_file = [
('图像/视频', '*.png;*.jpeg;*.jpg;*.tiff;*.bmp;*.mp4;*.avi'),
('图像', '*.png;*.jpeg;*.jpg;*.tiff;*.bmp'),
('视频', '*.mp4;*.avi'),
('全部文件', '*.*'),
]
# 输入文件路径
file_input = ''
# 输出文件路径
file_output = ''
# 视频/图像 超分
is_VideoImage = 'image' # 默认为图像超分
# 超分算法
# 图像超分辨率算法:SRCNN FSRCNN
# 视频超分辨率算法:EDVR
use_ways = 'SRCNN'
# 使用训练模型
use_model = "SRCNN_INx2"
# 模型
model_srcnn = [
"SRCNN_91x2",
"SRCNN_91x3",
"SRCNN_91x4",
"SRCNN_INx2",
"SRCNN_INx3",
"SRCNN_INx4",
]
model_fsrcnn = [
"FSRCNN_x2",
"FSRCNN_x3",
"FSRCNN_x4",
"FSRCNN-s_x2",
"FSRCNN-s_x3",
"FSRCNN-s_x4",
]
"""
用到的功能函数
"""
# 格式化地址
def formatLocal(local):
ans = local.replace('/', '\\') # 替换字符
return ans
# 根据输入文件路径 得到输出文件路径
def getOutputFile(infile):
# 分割input后缀(从右侧分割’.')
outfile = infile.rsplit('.', 1)[0] + '_out.' + infile.rsplit('.', 1)[1]
return outfile
# 更新 List组件
def renewList(listbox, content):
""" 将 listbox 更新为 content"""
global use_model
# 清空列表
listbox.delete(0, END)
# 往列表里添加数据
for item in content:
listbox.insert("end", item)
# 模型参数 更新为list组件首选项
use_model = listbox.get(0)
listbox.selection_set(0) # 首选项选中
# 更新 算法选项组件
def renewRadioVI(radio1, radio2, listbox):
""" 根据 程序属性配置 更新 算法选项组件"""
global is_VideoImage
if is_VideoImage == 'image': # 图像
# 更新 算法选项
radio1.config(text='SRCNN', value='SRCNN', command=lambda: func_Ways(ch='SRCNN', listbox=listbox))
radio2.config(text='FSRCNN', value='FSRCNN', command=lambda: func_Ways(ch='FSRCNN', listbox=listbox))
elif is_VideoImage == 'video': # 视频
radio1.config(text='SRCNN-v', value='SRCNN-v', command=lambda: func_Ways(ch='SRCNN-v', listbox=listbox))
radio2.config(text='FSRCNN-V ', value='FSRCNN-v', command=lambda: func_Ways(ch='FSRCNN-v', listbox=listbox))
else:
print("error:更新 算法选项 失败")
print(" is_VideoImage:" + str(is_VideoImage))
# 检查 输入文件
def checkFileFormat(infile):
# 检查路径
if file_input == "" or file_output == "":
print("error: 检查格式 路径为空 ")
return False
# 检查格式
informat = infile.rsplit('.', 1)[1]
if is_VideoImage == 'image':
if informat in format_im:
return True
print("error: 检查格式 格式不匹配 ")
elif is_VideoImage == 'video':
if informat in format_vi:
return True
print("error: 检查格式 格式不匹配 ")
else:
print("error:检查格式 参数错误 ch-is_VideoImage:" + str(is_VideoImage))
return False
# 调用exe SRCNN
def run_SRCNN():
global use_model
# 详细了解 见 SRCNN_test/ README
cmd = 'SRCNN.exe ' + file_input + ' ' + file_output + ' Model\\SRCNN\\' + use_model + '.mat'
print('cmd:' + cmd)
mystd.myPopenTime(cmd) # 运行cmd
return
# 调用exe FSRCNN
def run_FSRCNN():
global use_model
cmd = 'FSRCNN.exe ' + file_input + ' ' + file_output + ' Model\\FSRCNN\\' + use_model + '.mat'
print('cmd:' + cmd)
mystd.myPopenTime(cmd) # 运行cmd
return
# 调用exe SRCNNv
def run_SRCNNv():
global use_model
cmd = 'SRCNNv.exe ' + file_input + ' ' + file_output + ' Model\\SRCNN\\' + use_model + '.mat'
print('cmd:' + cmd)
mystd.myPopenTime(cmd) # 运行cmd
return
# 调用exe FSRCNNv
def run_FSRCNNv():
global use_model
cmd = 'FSRCNNv.exe ' + file_input + ' ' + file_output + ' Model\\FSRCNN\\' + use_model + '.mat'
print('cmd:' + cmd)
mystd.myPopenTime(cmd) # 运行cmd
return
"""
图形界面 回调函数
"""
# 选择文件 按钮
def func_chooseFile(entryInput, entryOutput):
# 打开文件选择对话框 返回选择文件路径
filename = tk.filedialog.askopenfilename(
title='选择文件',
filetypes=format_file)
filename = formatLocal(filename) # 格式化路径
if filename:
# 分割字符串 处理文件路径
global file_input, file_output
file_input = filename
file_output = getOutputFile(filename)
print("输入文件:", file_input)
print("预输出文件:", file_output)
# 设置输入输出文本框内容
entryInput.config(state='normal') # 写入后设为只读
entryInput.delete(0, END) # 删除entry框内容
entryInput.insert(0, file_input) # entry显示当前路径
entryInput.config(state='readonly') # 写入后设为只读
entryOutput.config(state='normal')
entryOutput.delete(0, END)
entryOutput.insert(0, file_output)
entryOutput.config(state='readonly')
else:
print("error:选择文件 未找到该文件")
# 图像/视频 选项
def func_VideoImage(ch, radio1, radio2, listbox, r_way):
global use_ways, is_VideoImage
if ch == 'image': # 图像
# 参数更改
is_VideoImage = ch # 视频/图像参数
use_ways = 'SRCNN' # 算法参数
r_way.set('SRCNN') # 算法组件选中参数
# 组件更新
renewRadioVI(radio1, radio2, listbox) # 更新 算法选项
renewList(listbox, model_srcnn) # 更新 模型列表
elif ch == 'video': # 视频
is_VideoImage = ch
use_ways = 'SRCNN-v'
r_way.set('SRCNN-v')
renewRadioVI(radio1, radio2, listbox)
renewList(listbox, model_srcnn)
else:
print("error:图像/视频选项 ch-is_VideoImage:" + str(ch))
# 算法 选项
def func_Ways(ch, listbox):
global use_ways, is_VideoImage
# 模型选项组件 更新
if ch == 'SRCNN':
use_ways = ch # 算法参数 更改
renewList(listbox, model_srcnn) # 更新列表组件
elif ch == 'FSRCNN':
use_ways = ch
renewList(listbox, model_fsrcnn)
elif ch == 'SRCNN-v':
use_ways = ch
renewList(listbox, model_srcnn)
elif ch == 'FSRCNN-v':
use_ways = ch
renewList(listbox, model_fsrcnn)
else:
print("error:算法选项 ch-use_ways:" + str(ch))
# 模型 选项
def func_chModel(listbox):
global use_model
use_model = listbox.get(listbox.curselection()) # 模型参数 更新为list组件被选中的选项
# print("模型选择 use_model:" + str(use_model))
# 开始 按钮
def func_start():
print("======================================= 开始计算 参数如下 ====================================")
print(" 输入路径:" + str(file_input))
print(" 输出路径:" + str(file_output))
print(" 视频/图像:" + str(is_VideoImage))
print(" 算法:" + str(use_ways))
print(" 模型:" + str(use_model))
# 检查文件格式
if not checkFileFormat(file_input):
print("error:运行终止 检查文件未通过")
return False
print("检查文件格式:正确")
# 调用算法
if use_ways == 'SRCNN':
print("run:图像_SRCNN")
run_SRCNN()
elif use_ways == 'FSRCNN':
print("run:图像_FSRCNN")
run_FSRCNN()
elif use_ways == 'SRCNN-v':
print("run:视频_SRCNN")
run_SRCNNv()
elif use_ways == 'FSRCNN-v':
print("run:视频_FSRCNN")
run_FSRCNNv()
else:
print("error:运行终止 参数错误 use_ways:"+str(use_ways))
return False
print("--------------------------------------------- 完成 ------------------------------------------")
print()