关于pytesser的一些问题
2016-03-17 10:51
253 查看
最近几天在做python验证码的识别,主要是运用python的ocr库,可惜在安装的时候就出现了很多问题,在google,stackoverflow,baidu上都没有有效解决,无奈自力更生,从源码层面开始,一步一步开始排除bug。
WindowsError: [Error 2] 的意思一般是找不到可靠的文件。
解决方案:
1、将需要运行的文件,直接放在pytesser的包下。
2、如果包在site-packages下,可能如上问题会一直存在,弄了几次还是如此,问题应该是tesseract.exe执行程序不在环境变量中,大家可以自行更改,将其直接添加至环境变量中,懒的话就像方法1那么操作就行。
在pytesser.py文件中有:
This file must be .bmp or other Tesseract-compatible format
所以如果自己给的输入文件不能被很好支持,那么
- 直接使用
- 尽量使用
部分代码:
感兴趣的同学可以去看看程序源码,不长。
那该怎么着解决呢?
很简单 ,去包里找到tesseract.exe,双击它就行,会自动产生一个tesseract.log错误日志。
如果想使用tesseract.exe直接识别,格式为
2、 Tesseract
3、 或者我早csdn上的PyTesser资源
注:网上有教程说换tessdata的内容,不用换
Dependencies:
pytesser.py Main module for importing
util.py Utility functions used by pytesser.py
errors.py Interprets exceptions thrown by Tesseract
tesseract.exe Executable called by pytesser.py
tessdata/ Resources used by tesseract.exe
一、运行的主要问题如下:
Traceback (most recent call last): File "C:\Users\TF-2016\Desktop\spider\ruijie\ruijie.py", line 33, in <module> print image_file_to_string('11.png', graceful_errors=True) File "C:\Python27\lib\site-packages\pytesser\pytesser.py", line 48, in image_file_to_string call_tesseract(filename, scratch_text_name_root) File "C:\Python27\lib\site-packages\pytesser\pytesser.py", line 23, in call_tesseract proc = subprocess.Popen(args) File "C:\Python27\lib\subprocess.py", line 710, in __init__ errread, errwrite) File "C:\Python27\lib\subprocess.py", line 958, in _execute_child startupinfo) WindowsError: [Error 2]
WindowsError: [Error 2] 的意思一般是找不到可靠的文件。
解决方案:
1、将需要运行的文件,直接放在pytesser的包下。
2、如果包在site-packages下,可能如上问题会一直存在,弄了几次还是如此,问题应该是tesseract.exe执行程序不在环境变量中,大家可以自行更改,将其直接添加至环境变量中,懒的话就像方法1那么操作就行。
在pytesser.py文件中有:
This file must be .bmp or other Tesseract-compatible format
所以如果自己给的输入文件不能被很好支持,那么
- 直接使用
image\_to_string()函数容易失败,
- 尽量使用
image\_file\_to\_string(filename, cleanup=cleanup\_scratch\_flag, graceful\_errors=True),注意最后的graceful_errors=True,很有用,当然它已经设定了默认值,可以不用手工赋值。
二、还有一种错误是errors.py文件找不到tesseract.log文件
这个是因为,在pytesser.py文件中调用subprocess时,执行tesseract.exe引擎没有返回错误(即没有生成tesseract.log文件),虽然也没有输出所要的文件结果(即进入了需要参数为tesseract.log的函数)———听着很绕,总之就是出bug了。部分代码:
def check_for_errors(logfile="tesseract.log"): inf = file(logfile) text = inf.read() inf.close() # All error conditions result in "Error" somewhere in logfile if text.find("Error") != -1: raise Tesser_General_Exception, text
感兴趣的同学可以去看看程序源码,不长。
那该怎么着解决呢?
很简单 ,去包里找到tesseract.exe,双击它就行,会自动产生一个tesseract.log错误日志。
如果想使用tesseract.exe直接识别,格式为
tesseract.exe input_filename output_filename (eg:tesseract.exe default.png default)
最后,附点文件:
1、 PyTesser2、 Tesseract
3、 或者我早csdn上的PyTesser资源
注:网上有教程说换tessdata的内容,不用换
Dependencies:
pytesser.py Main module for importing
util.py Utility functions used by pytesser.py
errors.py Interprets exceptions thrown by Tesseract
tesseract.exe Executable called by pytesser.py
tessdata/ Resources used by tesseract.exe
相关文章推荐
- JDBC借助Spring进行增删改查的操作--大大简化了程序
- ELK服务端安装部署
- BugHD for JavaScript上线,轻松收集前端 Error
- TableView的封装
- Java Script常用小脚本
- CentOS 7 安装 JDK8 详细步骤
- 堆排序
- MyCommTool串口工具使用方法
- Android内存泄漏分析及实践(一)
- fragment与activity之间通信整理
- docker迁移容器
- 转个堆与栈的区别
- 浅谈 RxAndroid + Retrofit + Databinding
- Forms authenctication cookie issue
- python网络学习(02)
- Linux基础回顾之基础命令五(用户及组)
- 静态路由命令配置
- Tomcat 输入http://localhost:8080显示oracle说明
- UVa679 小球下落(树)
- C语言中的位移运算