1. 程式人生 > >解決 python中 使用tesserocr,Imag模組 處理驗證碼的問題

解決 python中 使用tesserocr,Imag模組 處理驗證碼的問題

python程式:

from PIL import Image
import tesserocr
imag=Image.open(r"path")
print(tesserocr.image_to_text(imag))

會報以下錯誤:

Traceback (most recent call last):

  File "F:/python code/project/key.py", line 5, in <module>
    print(tesserocr.image_to_text(imag))
  File "tesserocr.pyx", line 2401, in tesserocr._tesserocr.image_to_text

RuntimeError: Failed to init API, possibly an invalid tessdata path: F:\python code\project\


解決方案:

將安裝Tesseract-OCR的安裝目錄路徑下的 tessdata檔案複製,然後貼上到你的專案所在的資料夾下的scrips目錄下即可解決問題