|
|
|
@ -6,27 +6,32 @@ from tkinter import filedialog
|
|
|
|
|
|
|
|
|
|
import read_image
|
|
|
|
|
|
|
|
|
|
model=3
|
|
|
|
|
model=3 # 默认使用模型三
|
|
|
|
|
# 此函数用于选择模型一
|
|
|
|
|
def model_1():
|
|
|
|
|
global model
|
|
|
|
|
model = 1
|
|
|
|
|
print(model)
|
|
|
|
|
|
|
|
|
|
# 此函数用于选择模型二
|
|
|
|
|
def model_2():
|
|
|
|
|
global model
|
|
|
|
|
model = 2
|
|
|
|
|
print(model)
|
|
|
|
|
|
|
|
|
|
# 此函数用于选择模型三
|
|
|
|
|
def model_3():
|
|
|
|
|
global model
|
|
|
|
|
model = 3
|
|
|
|
|
print(model)
|
|
|
|
|
|
|
|
|
|
# 此函数用于调节笔的粗细以及颜色
|
|
|
|
|
def paint(event):
|
|
|
|
|
x1, y1 = (event.x - 20), (event.y - 20)
|
|
|
|
|
x2, y2 = (event.x + 20), (event.y + 20)
|
|
|
|
|
w.create_oval(x1, y1, x2, y2, fill="white", outline='white')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 此函数用于打开本地的图片
|
|
|
|
|
def open_image():
|
|
|
|
|
image_name = filedialog.askopenfilename(title='打开图片', filetypes=[('jpg,jpeg', '*.jpg')])
|
|
|
|
|
image_show = cv2.imread(image_name, cv2.IMREAD_GRAYSCALE)
|
|
|
|
@ -35,6 +40,7 @@ def open_image():
|
|
|
|
|
result = read_image.predeiction(image_name, model)
|
|
|
|
|
text.set(str(result))
|
|
|
|
|
|
|
|
|
|
# 此函数用于截取画板图片并进行识别
|
|
|
|
|
def screenshot(*args):
|
|
|
|
|
a = root.winfo_x()
|
|
|
|
|
b = root.winfo_y()
|
|
|
|
@ -48,14 +54,14 @@ def screenshot(*args):
|
|
|
|
|
|
|
|
|
|
text.set(str(result))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 此函数用于画布的位置以及颜色
|
|
|
|
|
def clear_canvas(event):
|
|
|
|
|
x1, y1 = (event.x - 2800), (event.y - 2800)
|
|
|
|
|
x2, y2 = (event.x + 2800), (event.y + 2800)
|
|
|
|
|
w.create_oval(x1, y1, x2, y2, fill="black", outline='black')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 此函数用于重置画板
|
|
|
|
|
def reset_canvas():
|
|
|
|
|
a = root.winfo_x()
|
|
|
|
|
b = root.winfo_y()
|
|
|
|
@ -69,6 +75,7 @@ root.geometry('600x400') # 规定窗口大小600*400像素
|
|
|
|
|
root.resizable(False, False) # 规定窗口不可缩放
|
|
|
|
|
root.title('数字识别')
|
|
|
|
|
|
|
|
|
|
# 调节位置
|
|
|
|
|
col_count, row_count = root.grid_size()
|
|
|
|
|
|
|
|
|
|
for col in range(col_count):
|
|
|
|
@ -77,40 +84,30 @@ for col in range(col_count):
|
|
|
|
|
for row in range(row_count):
|
|
|
|
|
root.grid_rowconfigure(row, minsize=20)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
text = StringVar()
|
|
|
|
|
text.set('')
|
|
|
|
|
w = Canvas(root, width=400, height=400, bg='black')
|
|
|
|
|
w.grid(row=0, column=0, rowspan=6)
|
|
|
|
|
label_1 = Label(root, text=' 识别的结果为:', font=('', 20))
|
|
|
|
|
label_1.grid(row=0, column=1)
|
|
|
|
|
result_label = Label(root, textvariable=text, font=('', 25), height=2, fg='red')
|
|
|
|
|
result_label.grid(row=1, column=1)
|
|
|
|
|
|
|
|
|
|
try_button = Button(root, text='模型1', width=7, height=2, command=model_1)
|
|
|
|
|
try_button.grid(row=2, column=1,sticky=W)
|
|
|
|
|
try_button = Button(root, text='模型2', width=7, height=2, command=model_2)
|
|
|
|
|
try_button.grid(row=2, column=1)
|
|
|
|
|
try_button = Button(root, text='模型3', width=7, height=2, command=model_3)
|
|
|
|
|
try_button.grid(row=2, column=1,sticky=E)
|
|
|
|
|
|
|
|
|
|
try_button = Button(root, text='开始识别', width=15, height=2, command=screenshot)
|
|
|
|
|
try_button.grid(row=3, column=1)
|
|
|
|
|
|
|
|
|
|
clear_button = Button(root, text='清空画布', width=15, height=2, command=reset_canvas)
|
|
|
|
|
clear_button.grid(row=4, column=1)
|
|
|
|
|
|
|
|
|
|
load_image_button = Button(root, text='来自图片', width=15, height=2, command=open_image)
|
|
|
|
|
load_image_button.grid(row=5, column=1)
|
|
|
|
|
|
|
|
|
|
w.bind("<B1-Motion>", paint)
|
|
|
|
|
w.bind("<Button-3>", screenshot)
|
|
|
|
|
w.bind("<Double-Button-1>", clear_canvas)
|
|
|
|
|
|
|
|
|
|
mainloop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w = Canvas(root, width=400, height=400, bg='black') # 定义画布大小及其颜色
|
|
|
|
|
w.grid(row=0, column=0, rowspan=6) # 按键定义几行几列
|
|
|
|
|
label_1 = Label(root, text=' 识别的结果为:', font=('', 20)) # 字体显示大小
|
|
|
|
|
label_1.grid(row=0, column=1) # 该字体处于的位置
|
|
|
|
|
result_label = Label(root, textvariable=text, font=('', 25), height=2, fg='red') # 识别结果的大小和颜色定义
|
|
|
|
|
result_label.grid(row=1, column=1) # 识别结果处于的位置
|
|
|
|
|
|
|
|
|
|
try_button = Button(root, text='模型1', width=7, height=2, command=model_1) # 调用模型一函数
|
|
|
|
|
try_button.grid(row=2, column=1,sticky=W) # 该按钮所处的位置
|
|
|
|
|
try_button = Button(root, text='模型2', width=7, height=2, command=model_2) # 调用模型二函数
|
|
|
|
|
try_button.grid(row=2, column=1) # 该按钮所处的位置
|
|
|
|
|
try_button = Button(root, text='模型3', width=7, height=2, command=model_3) # 调用模型三函数
|
|
|
|
|
try_button.grid(row=2, column=1,sticky=E) # 该按钮所处的位置
|
|
|
|
|
|
|
|
|
|
try_button = Button(root, text='开始识别', width=15, height=2, command=screenshot) # 调用识别数字函数
|
|
|
|
|
try_button.grid(row=3, column=1) # 该按钮所处的位置
|
|
|
|
|
clear_button = Button(root, text='清空画布', width=15, height=2, command=reset_canvas) # 调用清空画布函数
|
|
|
|
|
clear_button.grid(row=4, column=1) # 该按钮所处的位置
|
|
|
|
|
load_image_button = Button(root, text='来自图片', width=15, height=2, command=open_image) # 调用打开本地图片函数
|
|
|
|
|
load_image_button.grid(row=5, column=1) # 该按钮所处的位置
|
|
|
|
|
|
|
|
|
|
w.bind("<B1-Motion>", paint) # 鼠标左键进行写数字
|
|
|
|
|
w.bind("<Button-3>", screenshot) # 鼠标右键进行截屏识别
|
|
|
|
|
w.bind("<Double-Button-1>", clear_canvas) # 双击鼠标左键进行清空画布
|
|
|
|
|
mainloop()
|