Python驗證碼通過pytesser識別


Python安裝包:

需要安裝的包主要有兩個: PIL 和 pytesser 、tesseract

(1)、安裝PIL:下載地址:http://www.pythonware.com/products/pil/

下載后是一個exe程序,直接雙擊安裝

(2)、pytesser:下載地址:http://code.google.com/p/pytesser/

pytesser 模塊的安裝:

下載后得到 “pytesser.zip”,是一個壓縮文件,使用方法: 

1、在 “C:\Python27\Lib\site-packages” 路徑下新建一個文件夾,命名 “pytesser” 。把 “pytesser.zip” 里的文件解壓到該目錄:

2、將 “pytesser.py” 改名為 “__init__.py”。

3、打開 “__init__.py” 文件,修改:tesseract_exe_name = 'C:\\Python27\\Lib\\site-packages\\pytesser\\tesseract' # Name of executable to be called at command line

4、pytesser 模塊依賴於 PIL 模塊,如果是按照上面的方法安裝 PIL 的話,需要把 “init.py” 文件里的 “import Image” 改成 “from PIL import Image” 。

下載解壓后直接放C:\Python27\Lib\site-packages,同時,新建一個pytesser.pth,內容就寫,注意這里的內容一定要和pytesser這個文件夾同名,意思就是pytesser文件夾,pytesser.pth,及內容都要一樣!

(3)、Tesseract OCR engine下載:http://code.google.com/p/tesseract-ocr/

下載后解壓,tessdata文件夾,用其替換掉pytesser解壓后的tessdata文件夾即可。(就上面的pytesser文件夾)

代碼如下:

1 #-*- coding:utf-8 -*-
2 __author__ = "carry"
3 from PIL import Image
4 from pytesser import *
5 
6 image = Image.open('xx.jpg')
7 print image_to_string(image)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM