1. 程式人生 > >python_安裝tesserocr後呼叫image_to_text報錯_Failed to init API, possibly an invalid tessdata path:

python_安裝tesserocr後呼叫image_to_text報錯_Failed to init API, possibly an invalid tessdata path:

問題描述:在tesserocr後使用使用image_to_text依舊報錯,如下:

import tesserocr
from PIL import Image

image = Image.open("test.jpg")
res = tesserocr.image_to_text(image)
print(res)

Traceback (most recent call last):
  File "E:/project/allow/hu/測試.py", line 4, in <module>
    res = tesserocr.image_to_text(image)
  File "tesserocr.pyx", line 2407, in tesserocr._tesserocr.image_to_text
RuntimeError: Failed to init API, possibly an invalid tessdata path: E:\project\venv\Scripts\/tessdata/

解決:tesseract檔案,安裝後將安裝路徑下在tessdata放到系統報錯在路徑下即可,我的路徑是“E:\project\venv\Scripts\”,

下載的安裝包

tesseract-ocr-w64-setup-v4.0.0-rc3.20181014.exe

tesseract安裝目錄:

py檔案執行的報錯的路徑:

再次執行py檔案:執行成功!!