1
img = printscreen_pil
img = img.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(img)
img = enhancer.enhance(2)
img = img.convert('1')
img.save('temp.jpg')
text = pytesseract.image_to_string(Image.open('temp.jpg'))
我想读取图像以将其转换为文本,但我得到错误系统找不到指定的文件。我认为它与python的工作目录有关。如果这是一个愚蠢的问题,我很抱歉,但我希望你能帮助我。python上的FileNotFoundError
这是完整的错误mssg。
Traceback (most recent call last):
File "C:\Users\pncor\Documents\pyprograms\bot.py", line 23, in <module>
text = pytesseract.image_to_string(Image.open('temp.jpg'))
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
的形象和你的脚本应该是在同一目录... –
错误非常明显;检查您的图片是否与您的python脚本位于相同的目录中,因为您相对引用它 – Vinny
如果您可以发布完整的错误并指出引起该错误的行,则帮助会更容易。我猜这是因为它没有找到名为'1'的文件而触发错误的“img.convert('1')”行。也许它实际上是'1.jpg'或类似的东西?但我只是猜测信息不足。 –