一、安装依赖库
pip install pytesseract
"""若是出现安装错误的情况,安装不了的时候,可以将命令改为 pip.exe install pytesseract来安装
若是将pip修改为pip.exe安装成功后,那么下文的所有pip都需要改为pip.exe"""
pip install PIL
"""若是失败了可以如下修改 pip install PILLOW"""
安装识别引擎tesseract-ocr(包含安装包及安装步骤)
- 下载 tesseract-ocr,https://blog.csdn.net/qq_41030861/article/details/99842001?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242 (可以先看第三章、踩坑)
二、代码
from PIL import Image
import pytesseract
imageObject = Image.open(r"C:\Users\gw\Desktop\xiazai4.png")# 文件所在位置
print(imageObject)
print(pytesseract.image_to_string