python破解验证码,python验证码,有开源的tesserac


有开源的tesseract-ocr在,如何用python来调用呢?好在有python-tesseract的封装。

如何安装?

我的系统是CentOS 6.3,用以下方法安装

yum groupinstall "Development Tools" -yyum -y install wget cmake yum -y install libjpeg-devel libpng-devel libtiff-devel zlib-develyum -y install gcc gcc-c++ make numpywget http://www.leptonica.com/source/leptonica-1.69.tar.gztar zxvf leptonica-1.69.tar.gzcd leptonica-1.69./configure --prefix=/usrmakemake installcd ..wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.3/OpenCV-2.4.3.tar.bz2tar jxvf OpenCV-2.4.3.tar.bz2cd OpenCV-2.4.3cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr -D BUILD_PYTHON_SUPPORT=ON .makemake installcd ..svn checkout http://tesseract-ocr.googlecode.com/svn/trunk/ tesseract-ocrcd tesseract-ocr/./autogen.sh./configure --prefix=/usrmakemake installcp tessdata/eng* /usr/share/tessdatacd ..wget http://peak.telecommunity.com/dist/ez_setup.pypython ez_setup.py easy_install pipyum install python-devel -ysvn checkout http://python-tesseract.googlecode.com/svn/trunk/ python-tesseractcd python-tesseractpython setup.py buildpython setup.py installcd test-slimrm *.pycrm *.pydpython test.py

如果可以正常输出,安装就没错了。如果出现

[root@MYVPS test-slim]# python test.pyTraceback (most recent call last):  File "test.py", line 4, in <module>    import tesseract  File "/usr/lib64/python2.6/site-packages/python_tesseract-tesseract-py2.6-linux-x86_64.egg/tesseract.py", line 25, in <module>    _tesseract = swig_import_helper()  File "/usr/lib64/python2.6/site-packages/python_tesseract-tesseract-py2.6-linux-x86_64.egg/tesseract.py", line 21, in swig_import_helper    _mod = imp.load_module('_tesseract', fp, pathname, description)ImportError: libtesseract.so.3: cannot open shared object file: No such file or directory

执行以下:

ldconfig

即可

那么如何破解验证码呢?它的例子里面就有很多方法了。只写一个我用到的吧。

import tesseractapi = tesseract.TessBaseAPI()api.Init(".","eng",tesseract.OEM_DEFAULT)api.SetPageSegMode(tesseract.PSM_AUTO)x = tesseract.ProcessPagesFileStream('1.png',api)print x

评论关闭