【Python】Python简单的图片识

具体想要实现上面的代码需要安装两个包和一个引擎 在安装之前需要先安装好Python,pip并配置好环境变量


1.第一个包: pytesseract    pip install pytesseract

若是出现安装错误的情况,安装不了的时候,可以将命令改为 pip.exe install pytesseract来安装 若是将pip修改为pip.exe安装成功后,那么下文的所有pip都需要改为pip.exe

2.第二个包:PIL安装     pip install PIL

若是失败了可以如下修改 pip install PILLOW

3.安装识别引擎tesseract-ocr

下载 tesseract-ocr,进行默认安装 下载地址点击这里

具体代码可以看这里

from PIL import Image  import pytesseract    imageObject=Image.open('D://new.jpg')  print (imageObject)  print (pytesseract.image_to_string(imageObject))

识别图片

我们发现运行时报错了

解决方法(D:/Python 该路径为Python安装位置,因人而异) D:/Python/Lib/site-packages/pytesseract 下的 pytesseract.py文件做如下修改


执行成功看下结果: