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'或類似的東西?但我只是猜測信息不足。 –