"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"
}