算法都是别人的,咱们只负责拿来用
没办法,水平有限
成品:
![](https://i-blog.csdnimg.cn/blog_migrate/8b6a87deddc4c31ea78b4b4e1d06047f.png)
图片:
![](https://i-blog.csdnimg.cn/blog_migrate/6d41d585eff874fe754b1c2ea5d9c051.png)
效果
![](https://i-blog.csdnimg.cn/blog_migrate/5689a7b150d3b4f22dfadf1cfd2dcdbb.png)
原码:
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()