内容简介:主要思路是根据需要识别语言配置(参照比如我这边是4.0版本,我需要的是对英文的ocr识别(识别英文的验证码),我就直接下载4.00版本的
主要思路是根据 教程 使用源码安装完tesseract后,然后通过安装pillow与pytesseract打通 python 进行在python代码中引用使用。
I. 依赖安装
brewinstallautomake autoconf libtool brewinstallpkgconfig brewinstallicu4c brewinstallleptonica brewinstallgcc
II. Tesseract编译安装
git clone https://github.com/tesseract-ocr/tesseract/ cd tesseract ./autogen.sh ./configure CC=gcc-8 CXX=g++-8 CPPFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib make -j sudo make install # if desired
III. 语言配置
需要识别语言配置(参照 教程 ):
- 前面安装完后,你会发现在
/usr/local/share/tessdata
会有默认的data,将export TESSDATA_PREFIX='/usr/local/share/tessdata'
配置到系统环境中 - 在 这里 下载对应版本的语言包
- 将下载的语言包直接放到这个
/usr/local/share/tessdata
比如我这边是4.0版本,我需要的是对英文的ocr识别(识别英文的验证码),我就直接下载4.00版本的 eng.traineddata
:
然后再将下载下来的 eng.traineddata
放到到 /usr/local/share/tessdata
中即可:
IV. 打通Python
这边打通python直接通过 pytesseract ,十分方便。
先安装pillow:
pip install pillow
再安装pytesseract:
pip install pytesseract
安装完成后就可以通过其在python中使用了,如:
try: from PIL import Image except ImportError: import Image import pytesseract # Simple image to string print(pytesseract.image_to_string(Image.open('test.png'))) # French text image to string print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'))
更多使用方法参照 官方 的文档。
以上所述就是小编给大家介绍的《Python爬虫验证码识别(使用Tesseract OCR识别)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 微博爬虫与水军识别(基于文本分析),超高准确率
- 中文项目:快速识别验证码,CNN也能为爬虫保驾护航
- 【动图详解】通过 User-Agent 识别爬虫的原理、实践与对应的绕过方法
- 爬虫需谨慎,那些你不知道的爬虫与反爬虫套路!
- 反爬虫之字体反爬虫
- 反爬虫之字体反爬虫
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Machine Learning in Action
Peter Harrington / Manning Publications / 2012-4-19 / GBP 29.99
It's been said that data is the new "dirt"—the raw material from which and on which you build the structures of the modern world. And like dirt, data can seem like a limitless, undifferentiated mass. ......一起来看看 《Machine Learning in Action》 这本书的介绍吧!