python识别图片中的文字处理方法

一、准备工作与代码实例

1、python2.7,PIL、pytesser

(1)安装PIL:下载地址:http://www.pythonware.com/products/pil/

下载后是一个exe,直接双击安装,它会自动安装到C:\Python27\Lib\site-packages中去,

(2)pytesser:下载地址:http://code.google.com/p/pytesser/,(CSDN下载

下载解压后直接放C:\Python27\Lib\site-packages(根据你安装的Python路径而不同),同时,新建一个pytesser.pth,内容就写pytesser,注意这里的内容一定要和pytesser这个文件夹同名,意思就是pytesser文件夹,pytesser.pth,及内容都要一样!



(3)将 'C:\Python27\Lib\site-packages\pytesser\pytesser.py' 里面的 tesseract_exe_name='tesseract' 里面是相对路径,改成绝对路径就好了:tesseract_exe_name='F:\\Python\\Lib\\site-packages\\pytesser\\tesseract', 将 import Image 改为 from PIL import Image

(4):

然后当安装好后运行:

from PIL import Image
from pytesser import * 


image = Image.open('captcha3.png') 
print image_to_string(image)


问题一、WindowsError: [Error 2] 

问题详细提示,如下:


产生原因: 调用tesseract.exe失败

解决:把tesseract.exe加入当前工程,如图:



说明:这个tesseract.exe就相当于在linux下的 tesseract-orc


问题二、IOError: [Errno 2] No such file or directory: 'tesseract.log'

问题详细提示,如下:


产生原因: 不是因为缺少tesseract.log而是因为缺少tessdata文件夹

解决:把tessdata文件夹从pytesser文件夹下拷贝到工程下,如图:



如果仍旧出现问题二,则试试换个tesseract.exe试试。



 
 

猜你喜欢

转载自blog.csdn.net/huxiangen/article/details/78812945
今日推荐