Python实现OCR识别:pytesseract

本文介绍了如何使用Python的pytesseract库进行OCR文字识别,强调了在安装和使用过程中遇到的TesseractNotFoundError问题。解决方法包括安装pillow、pytesseract、tesseract以及leptonica,特别是通过brew安装tesseract。完成环境配置后,展示了一段代码示例,成功识别并输出图片中的文字到output.txt文件。
摘要由CSDN通过智能技术生成

Python常用pytesseract进行图片上的文字识别,即OCR识别,完整的代码比较简单,只要下面一行即可,但是实际使用时环境配置上容易出错。

from PIL import Image
import pytesseract

text = pytesseract.image_to_string(Image.open('/Users/alice/Documents/Develop/PythonCode/textinphoto.PNG'))
print(text)

因此使用前,需要先安装pillow和pytesseract依赖包。

然而运行时仍然报错,raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path

原因是因为未安装tesseract,然后使用pip3 install tesseract之后仍然提示错误,如图:

alicedembp:~ alice$ pip3 install tesseract
Requirement already satisfied: tesseract in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.1.3)
alicedembp:~ alice$ tesseract
-bash: tesseract: command not found

无法使用,往上

  • 5
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值