0
私はpytesseract
を使用してイメージをテキストとしてテキストとして読み込みます。以下の私のコードです:FileNotFoundError:[WinError 2] pytesseract python-3.xの使用中に指定されたファイルが見つかりません
from PIL import Image
from pytesseract import image_to_string
import os.path
if (os.path.exists('image.png')):
filename = 'image.png'
image = Image.open(filename)
image.show()
s = image_to_string(Image.open(filename))
else:
print('Does not exist')
コードは、ファイルimage.png
を取得し、それを開くと、ファイルがそのディレクトリに存在することを意味する私に画像を表示します。しかし、次の行に行くと、s = image_to_string(Image.open(filename))
は次のエラーを出します。
Traceback (most recent call last):
File "C:/Users/hp/Desktop/GII/Genetic_Algorithm.py", line 8, in <module>
s = image_to_string(Image.open(filename))
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
config=config)
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
私は努力しましたが、これを処理する方法はわかりません。
同じエラーが再び発生しています。私はImage.open(ファイル名)を使って画像を開くことができるので、PILは問題を作りませんが、上記のエラーが表示されたら 'pytesseract'を使用しているときに発生しています。 – muazfaiz
他のアイデア;ファイルを2回開くので、2回目にファイルは使用できません。だから、多分 "s = image_to_string(image)"を試してみてください。 – stonebig
私はあなたが言っていることを正確には得ていませんでした。私はファイルを2度開いても、パスの問題は変わらないと思う。あなたは直感を書くことができますか?ありがとう – muazfaiz