尝试使用pytesseract进行OCR时的FileNotFoundError

时间:2017-08-08 20:28:01

标签: python popen

即使查看了subprocess.py的代码,我也无法弄清楚它想要找到什么。

错误:

Traceback (most recent call last):
  File "C:\Users\jopa0_000\OneDrive\Koodaus\Python\Map the hex\OCR.py", line 13, in <module>
    print(pytesseract.image_to_string(Image.open(file)))
  File "C:\Users\jopa0_000\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
    config=config)
  File "C:\Users\jopa0_000\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
    proc = subprocess.Popen(command, stderr=subprocess.PIPE)
  File "C:\Users\jopa0_000\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\jopa0_000\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Määritettyä tiedostoa ei löydy

代码:

from PIL import Image
import pytesseract
import os


pytesseract.pytesseract.tesseract_cmd = "C:\Program Files (x86)\Tesseract-OCR\tesseract.exe"

image_filenames = os.listdir('screens')

file = "C:\\Users\jopa0_000\OneDrive\Koodaus\Python\Map the hex\screens\\" + image_filenames[0]
print(file)

print(pytesseract.image_to_string(Image.open(file)))

0 个答案:

没有答案