2017-06-15 5 views
-1

openCVとPythonで画像からテキストを読み込むための基本的なスクリプトを作成しています。Python:Image to text

今、私はこのエラーを打ち明けましたが、ファイルが見つかりませんでした。問題はこのトレースバックを理解できません。どのファイルがありませんか?ライブラリやその他の問題 これはthresh.pngとremovednoise.pngを書いています。

私はPython 3.6で作業していますが、互換性の問題があれば教えてください。 詳細情報が必要な場合は、私にお知らせください。

私は指示に指向して助けてください。事前に感謝

私のコードです。

import cv2 
import numpy as np 
import pytesseract 
from PIL import Image 

#src_path ="D:/python'/practice" 

def get_string(img_path): 
    img = cv2.imread(img_path) 
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 
    kernel = np.ones((1, 1), np.uint8) 
    img = cv2.dilate(img, kernel, iterations=1) 
    img = cv2.erode(img, kernel, iterations=1) 

    cv2.imwrite("removed_noise.png", img) 
    img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2) 
    cv2.imwrite("thres.png", img) 
    result = pytesseract.image_to_string(Image.open("thres.png")) 

    return result 


print ('------------TEXT------------') 

print (get_string("imag1.png")) 

エラーメッセージ:

D:\python'\practice>python OCR_text.py 
------------TEXT------------ 
Traceback (most recent call last): 
    File "OCR_text.py", line 25, in <module> 
    print (get_string("imag1.png")) 
    File "OCR_text.py", line 18, in get_string 
    result = pytesseract.image_to_string(Image.open("thres.png")) 
    File "D:\Python\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string 
    config=config) 
    File "D:\Python\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract 
    proc = subprocess.Popen(command, stderr=subprocess.PIPE) 
    File "D:\Python\lib\subprocess.py", line 707, in __init__ 
    restore_signals, start_new_session) 
    File "D:\Python\lib\subprocess.py", line 990, in _execute_child 
    startupinfo) 
FileNotFoundError: [WinError 2] The system cannot find the file specified 

答えて

0

FileNotFoundErrorは、外部プロセスを起動しようとしているsubprocess、によって提起されています。起動しようとしているコマンドが見つかりません。

https://pypi.python.org/pypi/pytesseract/0.1

インストール:

File "D:\Python\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract 
    proc = subprocess.Popen(command, stderr=subprocess.PIPE) 

は、このセクションを参照して、システムにインストールされたいくつかの他の依存関係を必要とするpytesseractを使用するには、次のトレースバックでそれは言うまであなたは数行を見ることができます:

  • Python-tesseractにはPython 2.5以降が必要です。

  • Python Imaging Library(PIL)が必要です。 Debian/Ubuntuの下では、これはパッケージ "python-imaging"です。

  • google tesseract-ocrをhttp://code.google.com/p/tesseract-ocr/からインストールします。 tesseractコマンドは を "tesseract"として呼び出せなければなりません。そうでない場合は、 の例では、tesseractがPATHにないため、 を「tesseract.py」の先頭の「tesseract_cmd」変数に変更する必要があります。

それが動作しない場合、あなたはまだ、そのパッケージを使用するように設定されていない、コマンドシェルでtesseractを入力してみてください。インストール手順に従います。

+0

私はtesseractをC:ddirectoryにインストールしていて、D:directoryにpythonとpytestesseractを実行しているため、Tesseractがインストールされている可能性があります。 –

+0

その問題のみでした。私はCディレクトリからTesseractをアンインストールし、Dディレクトリにインストールしました。ありがとう兄貴 –