【问题标题】:Reading text from image with Pytesseract gives bad path error使用 Pytesseract 从图像中读取文本会导致路径错误
【发布时间】:2020-09-23 13:24:26
【问题描述】:

我正在尝试使用 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'])

那我该怎么办,我做错了什么? 有没有其他方法可以从图片中读取文字?

【问题讨论】:

    标签: python opencv computer-vision python-tesseract


    【解决方案1】:

    尝试打开模块源文件(以管理员身份)并编辑 Tesseract exe 文件的路径 - 如果需要,将其设置为绝对路径。它应该是顶行中的 const。

    类似这样的东西(在 Win 上):

    "C:\Program Files\Python36\Lib\site-packages\pytesseract\pytesseract.py" 设置路径:... pytesseract.tesseract_cmd = r"D:\OCR\tesseract.exe"

    https://github.com/Twenkid/ComputerVision_Pyimagesearch_OpenCV_Dlib_OCR-Tesseract-DL/blob/master/OCR_Tesseract/ocr.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      • 2022-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多