簡體   English   中英

使用 Pytesseract 從圖像中讀取文本會出現錯誤路徑錯誤

[英]Reading text from image with Pytesseract gives bad path error

我正在嘗試使用 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 文件的路徑 - 如果需要,將其設置為絕對路徑。 它應該是頂行中的常量。

像這樣(在 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM