识别简单的验证码
本实例只能识别简单的图片字符验证码,可以用于执行简单的自动化测试场景。
安装tesseract-ocr
tesseract-ocr的版本与语言包的版本必须对应
-
tesseract-ocr 各版本下载地址:
https://digi.bib.uni-mannheim.de/tesseract/
-
tesseract-ocr 各版本语言包下载地址:
https://github.com/tesseract-ocr/tesseract/wiki/Data-Files#cube-data-files-for-version-304305
安装库
pip install wheel
下载链接:
https://github.com/simonflueckiger/tesserocr-windows_build/releases
pip install tesserocr-2.2.2-cp36-cp36m-win_amd64.whl
pip install Pillow
第一次用ide使用tesseract的时候需要修改一下pytesseract.py中的tesseract_cmd指向的路径:
tesseract_cmd = r’C:\Program Files (x86)\Tesseract-OCR\tesseract.exe’
或者添加path环境变量,下载简体汉字、繁体汉字语言包,下载好之后放到安装目录的tessconfigs目录下即可。
使用
import pytesseract
from PIL import Image
print pytesseract.image_to_string(Image.open("D:\\Desktop\\1.png"),lang="eng",config="-psm 7")