pytesseract利用tesseract进行OCR文字识别。

依赖项

  1. pillow文档及安装
    pip install pillow

  2. tesseract下载点这儿
    tesseract下载并安装完后需要配置系统变量及tesseract变量。

     1. 配置系统变量    

    系统变量配置

     2. 配置tesseract变量

    tesseract变量配置

  3. pytesseract文档及安装
    pip install pytesseract

OCR使用

  1. pytesseract使用
from PIL import Image
import pytesseract

pytesseract.pytesseract.tesseract_cmd = n'<full_path_to_your_tesseract_executable>'

# 转成文字
print(pytesseract.image_to_string(Image.open('test.png')))

# 指定语言
print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang="fra'))
  1. tesseract使用
    tesseract 图像路径 输出.txt

注意事项

  1. 安装时选择需要的语言,若不能自动安装,参考这篇文章到这儿下载
  2. 语言包置于.\Tesseract-OCR\tessdata文件夹下