网站建设+荆州,视频剪辑制作教学,wordpress木马检测,php网站开发预算文档这是一个最简单的图像识别#xff0c;将图片加载后直接利用Python的一个识别引擎进行识别将图片中的数字通过 pytesseract.image_to_string(image)识别后将结果存入到本地的txt文件中1 #-*-encoding:utf-8-*-2 import pytesseract3 from PIL import Image4 5 class GetImageDa…这是一个最简单的图像识别将图片加载后直接利用Python的一个识别引擎进行识别 将图片中的数字通过 pytesseract.image_to_string(image)识别后将结果存入到本地的txt文件中 1 #-*-encoding:utf-8-*-2 import pytesseract3 from PIL import Image4 5 class GetImageDate(object):6 def m(self):7 image Image.open(ua.png)8 text pytesseract.image_to_string(image)9 return text
10
11 def SaveResultToDocument(self):
12 text self.m()
13 f open(uVerification.txt,w)
14 print text
15 f.write(str(text))
16 f.close()
17
18 g GetImageDate()
19 g.SaveResultToDocument() 具体想要实现上面的代码需要安装两个包和一个引擎 在安装之前需要先安装好Pythonpip并配置好环境变量 所有包的安装都是通过pip来安装的需要在windows PowerShell中进行并且是在 C:\Python27\Scripts目录下 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进行默认安装 安装完成后需要配置环境变量在系统变量path后增加 tesseract-ocr的安装地址C:\Program Files (x86)\Tesseract-OCR 一切都安装完成后运行上述代码会发现报错此时需要 至此结束转载于:https://www.cnblogs.com/tanghuang/p/6380588.html