Python 的图片文字识别

所用到的包

  • pip install pillow
  • pip install pytesseract
  • 安装tesseract-ocr-setup-4.00.00dev.exe,图片文字识别引擎
  • 安装语言包chi_sim.traineddata(简体中文)
  • 装完之后,找到你安装的pytesseract包,修改pytesseract.py中的tesseract_cmd=“C:\Program Files (x86)\Tesseract-OCR\tesseract.exe”
  • tesseract_cmd = path,这个是你图片文字识别引擎的安装路径,
  • 注意安装语言包:下载chi_sim.traineddata,放到C:\Program Files (x86)\Tesseract-OCR\tessdata\下即可,
  • 配置环境变量:在这里插入图片描述
  • 该环境变量是图片文字识别引擎环境变量。
  • 代码:
from PIL import Image # PIL是依赖pillow在python3中
import pytesseract # 图片文字识别库

code = pytesseract.image_to_string(Image.open("./test.png"),lang="chi_sim")#chi_sim简体中文
print(code)

测试图片效果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44224529/article/details/90513021