python 小工具--自动识别图片内的文字

算法都是别人的,咱们只负责拿来用
没办法,水平有限


成品:

图片:

 

效果


 原码:

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()

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值