【Python】Python简单的图片识别

来源:互联网 发布:淘宝组装机哪家好 编辑:程序博客网 时间:2024/05/29 03:16

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


1.第一个包: pytesseractpip 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 Imageimport pytesseractimageObject=Image.open('D://new.jpg')print (imageObject)print (pytesseract.image_to_string(imageObject))

识别图片
这里写图片描述

我们发现运行时报错了
这里写图片描述

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

这里写图片描述


执行成功看下结果:
这里写图片描述

原创粉丝点击