python - 使用 Pytesseract 从图像中读取文本会导致路径错误
问题描述
我正在尝试使用 pytesseract 从图像中读取文本。我正在使用 mac。我已经用 pip 安装了 pytesseract。
import cv2
import pytesseract
img = cv2.imread('slika1.png')
text = pytesseract.image_to_string(img)
print(text)
它给了我这个错误:
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
当我这样做时:
import importlib.util
print(importlib.util.find_spec('pytesseract'))
它打印:
ModuleSpec(name='pytesseract', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f8a7837c160>, origin='/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/__init__.py', submodule_search_locations=['/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract'])
那我该怎么办,我做错了什么?有没有其他方法可以从图像中读取文本?
解决方案
尝试打开模块源文件(以管理员身份)并编辑 Tesseract exe 文件的路径 - 如果需要,将其设置为绝对路径。它应该是顶行中的 const 。
像这样的东西(在Win上):
"C:\Program Files\Python36\Lib\site-packages\pytesseract\pytesseract.py" 设置路径:... pytesseract.tesseract_cmd = r"D:\OCR\tesseract.exe"
推荐阅读
- azure-logic-apps - 将文件从 FTP 复制到 Blob 存储
- php - 未定义索引:主机共享主机中的文件错误
- amazon-web-services - API Gateway 配置以接收正确的 POST 正文为 JSON
- python - 带有if条件循环的python列表理解
- javascript - 如果用户不在页面上,html5 geolocation.watchposition 会起作用吗?
- python - Azure Python SDK - 与 Azure AD 交互
- google-apps-script - 如何将添加到 Google 表格单元格中的图像保存到 Google 云端硬盘?
- node.js - 如何在 Typescript 中下载文件(从 URL)
- c++ - C++ 重载/匹配 N 个嵌套模板
- shortest-path - 对于无向边加权图,如何找到从顶点 v 到顶点 w 的最短路径?