python识别图像上的文字

环境:

pycharm

python3.7

tesseract-ocr(下载地址https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-4.00.00dev.exe)

1、导入以下两个package

from PIL import Image
import pytesseract

2、进入project***\venv\Lib\site-packages\pytesseract目录,修改pytesseract.py配置,添加tesseract路径

3、代码

# -*- coding: utf-8 -*-
from PIL import Image
import pytesseract

text=pytesseract.image_to_string(Image.open('d:/m2.png'))
print(text)

按照前序步骤配置,此时就可以读取图片上的数据了。

如本地要使用tesseract-ocr,则需要设置环境变量,电脑-属性-高级-环境变量

 
发布了123 篇原创文章 · 获赞 12 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/haiziccc/article/details/102492308