2017-06-26 8 views
1

"Document Text Detection"サンプルアップローダの出力をGoogle Vision APIで再現しようとしています。しかし、私がsample codeから得ている出力は、単語をまとめてグループ化する必要がある場合にのみ、出力として個々の文字を提供しています。Google Vision APIから完全な単語としてテキストをグループ化する

ライブラリには、DOCUMENT_TEXT_DETECTエンドポイントではなく「単語」でグルーピングする機能がありますか、またはPythonでimage.detect_full_text()機能を使用できますか?

私の.jpgファイルは、image.detect_text()の機能が満たされるように視覚的に構造化されていないため、フルテキスト抽出を探していません。

Googleのサンプルコード:

def detect_document(path): 
    """Detects document features in an image.""" 
    vision_client = vision.Client() 

    with io.open(path, 'rb') as image_file: 
     content = image_file.read() 

    image = vision_client.image(content=content) 

    document = image.detect_full_text() 

    for page in document.pages: 
     for block in page.blocks: 
      block_words = [] 
      for paragraph in block.paragraphs: 
       block_words.extend(paragraph.words) 

      block_symbols = [] 
      for word in block_words: 
       block_symbols.extend(word.symbols) 

      block_text = '' 
      for symbol in block_symbols: 
       block_text = block_text + symbol.text 

      print('Block Content: {}'.format(block_text)) 
      print('Block Bounds:\n {}'.format(block.bounding_box)) 

Googleが提供する既製品のサンプルのサンプル出力:

property { 
    detected_languages { 
    language_code: "mt" 
    } 
} 
bounding_box { 
    vertices { 
    x: 1193 
    y: 1664 
    } 
    vertices { 
    x: 1206 
    y: 1664 
    } 
    vertices { 
    x: 1206 
    y: 1673 
    } 
    vertices { 
    x: 1193 
    y: 1673 
    } 
} 
symbols { 
    property { 
    detected_languages { 
     language_code: "en" 
    } 
    } 
    bounding_box { 
    vertices { 
     x: 1193 
     y: 1664 
    } 
    vertices { 
     x: 1198 
     y: 1664 
    } 
    vertices { 
     x: 1198 
     y: 1673 
    } 
    vertices { 
     x: 1193 
     y: 1673 
    } 
    } 
    text: "P" 
} 
symbols { 
    property { 
    detected_languages { 
     language_code: "en" 
    } 
    detected_break { 
     type: LINE_BREAK 
    } 
    } 
    bounding_box { 
    vertices { 
     x: 1200 
     y: 1664 
    } 
    vertices { 
     x: 1206 
     y: 1664 
    } 
    vertices { 
     x: 1206 
     y: 1673 
    } 
    vertices { 
     x: 1200 
     y: 1673 
    } 
    } 
    text: "M" 
} 


block_words 
Out[47]: 
[property { 
    detected_languages { 
    language_code: "en" 
    } 
} 
bounding_box { 
    vertices { 
    x: 1166 
    y: 1664 
    } 
    vertices { 
    x: 1168 
    y: 1664 
    } 
    vertices { 
    x: 1168 
    y: 1673 
    } 
    vertices { 
    x: 1166 
    y: 1673 
    } 
} 
symbols { 
    property { 
    detected_languages { 
     language_code: "en" 
    } 
    } 
    bounding_box { 
    vertices { 
     x: 1166 
     y: 1664 
    } 
    vertices { 
     x: 1168 
     y: 1664 
    } 
    vertices { 
     x: 1168 
     y: 1673 
    } 
    vertices { 
     x: 1166 
     y: 1673 
    } 
    } 
    text: "2" 
} 

答えて

0

この応答が遅れて来ています。私はあなたが以下のようなものを探していたと思います。

def parse_image(image_path=None): 
    """ 
    Parse the image using Google Cloud Vision API, Detects "document" features in an image 
    :param image_path: path of the image 
    :return: text content 
    :rtype: str 
    """ 

    client = vision.ImageAnnotatorClient() 
    response = client.text_detection(image=open(image_path, 'rb')) 
    text = response.text_annotations 
    del response 

    return text[0].description 

この関数は画像に完全なテキストを返します。

0

GCV中の2つのタイプがあります 1.テキスト検出および2ドキュメントテキスト検出

テキスト検出は、画像内のテキストを検出するために使用されます。基本的に、それはそこにあるテキスト値を与えます。レシートや文書データの読み取りには使用できないなど、正確性に頼ることはできません。

ただし、ドキュメントのテキストの検出精度は非常に高く、ドキュメントから細かい詳細を検出します。この方法では、単語は互いに分離される。 03/12/2017は、座標と一緒に0 3/1 2 /などとなります。これはより正確な精度のためです。

質問に応じて、最初の方法、つまりテキスト検出を使用してください。完全な単語とその座標を含む結果が得られます。

関連する問題