安装
#安装imagemagick
brew install imagemagick
# 安装tesseract
# 后面加--all-languages会报错
# brew install tesseract --all-languages
# 替代方案
brew install tesseract
brew install tesseract-lang
# 安装tesserocr
# 以不使用二进制包方式安装 否则在使用时会出现import tesserocr会出现ImportError
pip install --no-binary :all: tesserocr
# 其他所需安装包
pip install selenium pillow numpy retrying
在Python3中使用
示例图片image.png
"""
使用OCR技术识别图形验证码
"""
import tesserocr
from PIL import Image
# 方式1
image = Image.open('image.png')
print(tesserocr.image_to_text(image))
# 方式2
print(tesserocr.file_to_text('image.png'))
运行结果:
解决import tesserocr 报错ImportError问题
# 以不使用二进制包方式安装 否则在使用时会出现import tesserocr会出现ImportError
pip install --no-binary :all: tesserocr