2017-10-08 10 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の作業ディレクトリと関係していると思います。これが愚かな質問であれば申し訳ありませんが、私があなたを助けてくれることを願っています。FileNotFoundError on Python

これは完全なエラーです。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は、OCRを実行するためにサブプロセスとしてtesseractバイナリを実行します。

ご使用のOSのパッケージマネージャを使用してインストールするか、installation documentationを参照してください。 Windowsを使用しているので、thisをチェックしてください。

また、私はそれだけでpytesseract.image_to_stringに直接渡し、最初のファイルに強調画像を書き込む必要があるとは思わない:画像

text = pytesseract.image_to_string(img) 
関連する問題