0
我使用pytesseract
在Python中以文本形式讀取圖像。以下是我的代碼:FileNotFoundError:[WinError 2]系統找不到使用pytesseract時指定的文件python-3.x
from PIL import Image
from pytesseract import image_to_string
import os.path
if (os.path.exists('image.png')):
filename = 'image.png'
image = Image.open(filename)
image.show()
s = image_to_string(Image.open(filename))
else:
print('Does not exist')
代碼獲取文件image.png
,打開它並顯示圖像給我,這意味着該文件在該目錄中存在。但是當它進入下一行s = image_to_string(Image.open(filename))
時,它會給出以下錯誤。
Traceback (most recent call last):
File "C:/Users/hp/Desktop/GII/Genetic_Algorithm.py", line 8, in <module>
s = image_to_string(Image.open(filename))
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
config=config)
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
我努力了,但不知道該如何處理。
我再次收到相同的錯誤。我thinl PIL不會產生問題,因爲我可以使用Image.open(文件名)打開圖像,但如果你看到上面的錯誤,當我使用'pytesseract'時會發生這種錯誤。 – muazfaiz
等想法;你打開兩次文件,所以第二次,該文件不可用。所以,也許嘗試「s = image_to_string(image)」 – stonebig
我並沒有完全得到你想說的話。我想即使我打開文件兩次它不會改變路徑問題。你能寫出你的直覺嗎?謝謝 – muazfaiz