2017-10-08 24 views
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 
+0

的形象和你的腳本應該是在同一目錄... –

+0

錯誤非常明顯;檢查您的圖片是否與您的python腳本位於相同的目錄中,因爲您相對引用它 – Vinny

+0

如果您可以發佈完整的錯誤並指出引起該錯誤的行,則幫助會更容易。我猜這是因爲它沒有找到名爲'1'的文件而觸發錯誤的「img.convert('1')」行。也許它實際上是'1.jpg'或類似的東西?但我只是猜測信息不足。 –

回答

3

tesseract包似乎並沒有被你的系統上安裝,或者它是不是你的路徑上找到。 pytesseract運行tesseract二進制作爲子進程以執行OCR。

使用您的操作系統上的軟件包管理器進行安裝,或參考installation documentation。您正在使用Windows,因此請檢查this

此外,我不認爲有必要寫增強的圖像先申請,只需直接將它傳遞給pytesseract.image_to_string

text = pytesseract.image_to_string(img)