解决ecplise+phthon2.7中使用pytesser和tesseract进行ocr,出现报错的问题

网上很多使用ecplise+phthon2.7中使用pytesser或者tesseract进行OCR网站验证码的案例,但配置起来实在让人崩溃。

通用步骤:
1、下载了pytesser_v0.0.1;

2、然后解压后拷贝到C:ProgramDataAnaconda2Libsite-packages;

3、文件夹名字改为pytesser;

4、然后在C:ProgramDataAnaconda2Libsite-packages文件夹下新建一个文件,起名为pytesser.pth,内容为pytesser

5、然后在C:ProgramDataAnaconda2Libsite-packagespytesserpytesser.py文件中第六行,更改import Image  为 from PIL import Image;

6、然后在ecplice界面中写代码:

from PIL import Image    
from pytesser import * im = Image.open('C:\ProgramData\Anaconda2\Lib\site-packages\pytesser\phototest.tif')
im.show()

没问题,图片顺利的打开了。

7、然后调用了下oCR的函数:

print image_to_string(im)

然后就无穷无尽的报错。

ecplice的错误提示还毫无帮助,只提示:

Traceback (most recent call last):
  File "C:UsersTF-2016Desktopspider
uijie
uijie.py", line 33, in <module>
    print image_file_to_string('11.png', graceful_errors=True)
  File "C:Python27libsite-packagespytesserpytesser.py", line 48, in image_file_to_string
    call_tesseract(filename, scratch_text_name_root)
  File "C:Python27libsite-packagespytesserpytesser.py", line 23, in call_tesseract
    proc = subprocess.Popen(args)
  File "C:Python27libsubprocess.py", line 710, in __init__
    errread, errwrite)
  File "C:Python27libsubprocess.py", line 958, in _execute_child
    startupinfo)
WindowsError: [Error 2] 

网上找了两个小时,很多人遇到这个问题,几乎没有解决的,最后发现有人说起了:http://blog.csdn.net/c465869935/article/details/51438576

  • qq_38717146

    2017-05-09 17:454楼
     回复
  • 刚刚碰巧给解决了。找到你的pytesseract.py这个文件,将其中的tesseract_cmd = 'tesseract'这行改为tesseract_cmd = r'C:/Program Files (x86)/Tesseract-OCR/tesseract.exe'即可。

然后我决定下载一个最新版的tesseract 3.0.2版,不再依靠pytesseract自带的那个1.01版本了。

下载后安装,然后在pytesseract.py中把tesseract_exe_name = 'tesseract' # Name of executable to be called at command line  改为:

tesseract_exe_name = r'C:/Program Files (x86)/Tesseract-OCR/tesseract.exe' #  'tesseract' Name of executable to be called at command line

然后运行,ok了,可以ocr英文和数字了。

但遗憾的是,中文库是谷歌的网址,下载不下来,如果能下载下来,很期待ocr中文的效果。

原文地址:https://www.cnblogs.com/telephoner/p/8424796.html