[原]Python 使用pytesseract库识别验证码(MAC系统)


1.安装python

brew install python


2.安装PIL及图片格式支持

下载
http://www.pythonware.com/products/pil/index.htm

解压
tar -xzf Imaging-1.1.7.tar.gz

安装PIL
cd Imaging-1.1.7
sudo python setup.py install

安装图片格式支持
brew install libpng
brew install jpeg
brew install libtiff

(注:安装了libtiff后PIL仍然无法支持tiff格式的图片,原因还没搞清楚)


3.安装leptonica

brew install leptonica


4.安装tesseract-ocr

brew install tesseract


5.安装pytesseract库

安装pip工具
sudo easy_install pip

安装pytesseract
sudo pip install pytesseract

6.写python脚本并运行

import pytesseract
from PIL import Image

image = Image.open('yzm.png')
image.load()
image.split()
vcode = pytesseract.image_to_string(image)
print vcode

其中yzm.png为验证码图片,和py脚本同一个目录

py脚本保存为yzm.py,运行之

python yzm.py

显示结果

原文地址:https://www.cnblogs.com/liuqing0328/p/5914074.html