2017-10-08 25 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)