数字加英文字母图像识别
提取 image.png 图片中的文字
APP987Y5T6C7一. 安装Tesseract-OCR.exe
下载地址:https://github.com/UB-Mannheim/tesseract/wiki
根据需要选择下载的版本
下载完成后,一路点击Next按钮,会出现如下图所示的页面。可以勾选Additional language data(download)来安装OCR识别支持的语言包,也可以勾选上Addition script data(download)将脚本数据也安装上。之后继续一路点击Next按钮即可。
二. 配置环境变量
安装路径如D:Tesseract-ocr,将该路径添加到系统变量path中
配置完成后,Win+R快捷键召唤出运行窗口,输入cmd 打开命令行,输入tesseract -v,出现下图所示页面,说明环境变量配置成功。
三. 修改pytesseract.py文件中的代码
找到pytesseract.py文件,如 D:pythonLibsite-packagespytesseractpytesseract.py
会出现Python中的pytesseract.py打不开情况
或 D:pycharmvenvLibsite-packagespytesseractpytesseract.py
将源码中的:
tesseract_cmd = 'tesseract'
修改为:
tesseract_cmd = r'D:tesseract ocrtesseract.exe'
四.下载好 pillow 和 pytesseract 这两个库
提取 image.png 图片中的文字
from PIL import Image import pytesseract image = Image.open(r'C:UsersAdministratorDesktopimage.png') content = pytesseract.image_to_string(image) print(content)



