赞
踩
- from PIL import Image
- import pytesseract
- #import tkMessageBox
- import tkinter as tk
- import tkinter.filedialog
- from tkinter.filedialog import askopenfilename
-
- def tess():
- global file_path,Image
- file_path=''
- file_path = askopenfilename(title='请打开要操作的文件',
- filetypes=[('图片', '*.jpg *.bmp *.png'), ('所有文件', '*')],
- initialdir='.\\')
- print('选择的导入文件是: ', file_path)
- # 显式指定 Tesseract 的安装路径
- pytesseract.pytesseract.tesseract_cmd = r'D:\Tesseract-OCR\tesseract.exe'
- Image = Image.open(file_path)
- str_text = pytesseract.image_to_string(Image,lang='chi_sim') #使用简体中文解析图片
- b1.insert(tk.INSERT, str_text)
- b1.insert(tk.INSERT, Image)
- return 0
-
- if __name__ == '__main__':
- window = tk.Tk()
- window.title('图文识别\' 1.0') # 窗口标题
- window.geometry('800x600') # 这里的乘是小x
-
- bn_open = tk.Button(window, text='选择文件', font=('Arial', 12), width=10, height=1, command=tess)
- bn_open.place(x=50, y=20)
- f = tk.Frame()
- s1 = tk.Scrollbar(f, orient=tk.VERTICAL)
- s2 = tk.Scrollbar(f, orient=tk.HORIZONTAL)
- b1 = tk.Text(f, fg='black', font=('Arial', 12), width=500, height=30, wrap=tk.NONE,
- yscrollcommand=s1.set, xscrollcommand=s2.set)
- s1.pack(side=tk.RIGHT, fill=tk.Y)
- s1.config(command=b1.yview)
- s2.pack(side=tk.BOTTOM, fill=tk.X)
- s2.config(command=b1.xview)
- b1.pack()
- f.pack(padx=10,pady=70)
- window.config(cursor="arrow")
- window.mainloop()
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。