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