Centos下實現使用tesseract破解驗證碼
阿新 • • 發佈:2018-12-16
實現使用tesseract實現自動識別驗證碼,然後使用python搭建守護程序進行監聽。
一、首先要安裝Python
centos下預設的最新版本是2.6.6,為了更好的相容性,我這裡安裝python2.7.11.1),先安裝GCC,用如下命令yum install gcc gcc-c++ openssl-devel 2)下載Python-2.7.11.tar.xz檔案,wget
tar -Jxvf Python-2.7.11.tar.xz
cd Python-2.7.11
mkdir /usr/local/python2.7
./configure --prefix=/usr/local/python2.7
make all
make install
清除之前編譯的可執行檔案及配置檔案。
make clean
清除所有生成的檔案 make distclean 由於系統預設給是2.6,所以先清除/usr/bin/python
rm -rf /usr/bin/python
建立軟連線
ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python
可以用python -V檢視, 安裝python擴充套件包
ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python
然後執行
python ez_setup.py 發現此方法安裝不上,出現問題,setup_tool安裝不上,去官網檢視,把ez_setup包下載下來。
wget https://pypi.python.org/packages/ba/2c/743df41bd6b3298706dfe91b0c7ecdc47f2dc1a3104abeb6e9aa4a45fa5d/ez_setup-0.9.tar.gz
tar zxvf ez_setup-0.9.tar.gz
cd ez_setup-0.9
python ez_setup.py
雖然現在python已經安裝完成,但是使用yum命令會有問題——yum不能正常工作:
# yum list
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python
這是因為yum預設使用的python版本是2.6.6,到哪是現在的python版本是2.7.5,故會出現上述問題,只需要該一下yum的預設python配置版本就行了:
#vi /usr/bin/yum
將檔案頭部的#!/usr/bin/python改為
#/usr/bin/python2.6
二、安裝tesseract
yum install -y tesseract
既可安裝,安裝的版本是3.04 安裝好後既可以使用其來使用進行圖片的識別,
tesseract phototest.tif phototest -l eng
他會生成一個phototest的檔案,裡面就是所識別得內容
三、安裝PIL
1)安裝PIL所需的系統庫檔案,參考PIL的REDEME檔案,需要如下依賴庫 yum install zlib zlib-devel libjpeg libjpeg-devel freetype freetype-devel 2)刪除Python下安裝的PIL cd /usr/local/python2.7/lib/python2.7/site-packages 3)下載PIL軟體包 wget http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz tar -zxvf Imaging-1.1.7.tar.gz cd Imaging-1.1.7 python setup.py build_ext -i #用來進行安裝前的檢查#修改setup.py,通過指令 vim setup.py 其中yum安裝的依賴庫需要用rpm -ql 包名檢視安裝位置。
TCL_ROOT = "/usr/lib64/"
JPEG_ROOT = "/usr/lib64/"
ZLIB_ROOT = "/usr/lib64/"
TIFF_ROOT = "/usr/lib64/"
FREETYPE_ROOT = "/usr/lib64/"
LCMS_ROOT = "/usr/lib64/"
安裝
$ python setup.py install
四、安裝pytesser
pytesser專案目前為止只有0.0.1版本,並且程式碼託管在谷歌,無法獲取,我是在百度網盤下載, 下載完成後,放到python安裝模組下 /usr/local/python2.7/lib/python2.7/site-packages/下 在其目錄下,可以進行測試 寫一個test.py指令碼 環境變數pythonpath 在/etc/profile.d/ vim pythonpath.sh 輸入: export PYTHONPATH=/usr/local/python2.7/lib/python2.7/site-packages/:/usr/local/python2.7/lib/python2.7/site-packages/pytesser_v0.0.1 儲存退出 source /etc/profile.d/pythonpath.sh 即可。
五、安裝web.py
官網:webpy.org
下載web.py
wget http://webpy.org/static/web.py-0.37.tar.gz
tar zxvf web.py-0.37.tar.gz
cd /web.py-0.37
python setup.py install
或者使用
/usr/local/python2.7/bin/easy_install web.py
把寫好的Python指令碼加入到系統啟動當中,並系統重啟自動啟動,後臺執行 在/etc/init.d/目錄下新建一個啟動指令碼名字叫做chimgtoword 在其中加入如下內容:
#!/bin/bash
#add for chkconfig
#chkconfig: 2345 70 30
#description: the description of the shell
#processname: chimgtoword
#author:
#date:
執行
nohup /usr/bin/python /usr/local/bin/changeImgToWords.py 2>>/dev/null &
儲存退出。
增加可執行許可權,
[[email protected] ~]# chmod a+x /etc/init.d/chimgtoword
[[email protected] ~]# chkconfig --add chimgtoword
[[email protected] ~]# chkconfig --list|grep chimgtoword
chimgtoword 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[[email protected] ~]# chkconfig chimgtoword on
啟動服務:
[[email protected] ~]# /etc/init.d/chimgtoword
檢視服務是否啟動
檢視埠是否開啟: