我正在使用Python 3.x,并使用以下代码将图像转换为文本:
我遇到了以下错误:
请注意,我已将图像放在与我的Python文件相同的目录中。同时,在
有什么想法是可能出了什么问题吗?谢谢。
from PIL import Image
from pytesseract import image_to_string
image = Image.open('image.png', mode='r')
print(image_to_string(image))
我遇到了以下错误:
Traceback (most recent call last):
File "C:/Users/hp/Desktop/GII/Image_to_text.py", line 12, in <module>
print(image_to_string(image))
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
请注意,我已将图像放在与我的Python文件相同的目录中。同时,在
image = Image.open('image.png', mode='r')
这一行并没有出现错误,但是在print(image_to_string(image))
这一行却出现了错误。有什么想法是可能出了什么问题吗?谢谢。
if (os.path.exists('image.png')): image = Image.open('image.png') print(image_to_string(image)) else: print('不存在')
但是遇到了相同的错误,这意味着文件存在,但尝试读取文本时会引发错误。 - muazfaiz