google 视觉 API returns 空边界框顶点,取而代之 returns normalised_vertexes
google vision API returns empty bounding box vertexes, instead it returns normalised_vertexes
我正在使用 vision.enums.Feature.Type.DOCUMENT_TEXT_DETECTION
提取 pdf 文档中的一些密集文本。这是我的代码:
from google.cloud import vision
def extract_text(bucket, filename, mimetype):
print('Looking for text in PDF {}'.format(filename))
# BATCH_SIZE; How many pages should be grouped into each json output file.
# """OCR with PDF/TIFF as source files on GCS"""
# Detect text
feature = vision.types.Feature(
type=vision.enums.Feature.Type.DOCUMENT_TEXT_DETECTION)
# Extract text from source bucket
gcs_source_uri = 'gs://{}/{}'.format(bucket, filename)
gcs_source = vision.types.GcsSource(uri=gcs_source_uri)
input_config = vision.types.InputConfig(
gcs_source=gcs_source, mime_type=mimetype)
request = vision.types.AnnotateFileRequest(features=[feature], input_config=input_config)
print('Waiting for the ORC operation to finish.')
ocr_response = vision_client.batch_annotate_files(requests=[request])
print('OCR completed.')
在响应中,我希望在 ocr_response.responses[1...n].pages[1...n].blocks[1...n].bounding_box
中找到一个 vertices
的列表,但这个列表是空的。相反,有一个 normalized_vertices
列表,它是 0 和 1 之间的规范化顶点。为什么会这样?为什么 vertices
结构是空的?
我正在关注 this 文章,那里的作者使用 vertices
,但我不明白为什么我没有得到它们。
为了将它们转换为非规范化形式,我将规范化的顶点乘以高度和宽度,但结果很糟糕,盒子没有很好地定位。
要将 Normalized Vertex 转换为 Vertex,您应该将 NormalizedVertex 的 x 字段乘以宽度值以获得 Vertex 的 x 字段,并将 NormalizedVertex 的 y 字段乘以高度值以获得顶点.
reason 为什么你得到 Normalized Vertex,而 Medium 文章的作者得到 Vertex 是因为 TEXT_DETECTION 和 DOCUMENT_TEXT_DETECTION 模型自 5 月 15 日以来已升级到较新的版本, 2020, medium文章写于2018年12月25日
要对结果使用遗留模型,您必须在要素对象的模型字段中指定 "builtin/legacy_20190601" 以获取旧模型结果。
但是 Google 的文档提到,2020 年 11 月 15 日之后将不再提供旧型号。
我正在使用 vision.enums.Feature.Type.DOCUMENT_TEXT_DETECTION
提取 pdf 文档中的一些密集文本。这是我的代码:
from google.cloud import vision
def extract_text(bucket, filename, mimetype):
print('Looking for text in PDF {}'.format(filename))
# BATCH_SIZE; How many pages should be grouped into each json output file.
# """OCR with PDF/TIFF as source files on GCS"""
# Detect text
feature = vision.types.Feature(
type=vision.enums.Feature.Type.DOCUMENT_TEXT_DETECTION)
# Extract text from source bucket
gcs_source_uri = 'gs://{}/{}'.format(bucket, filename)
gcs_source = vision.types.GcsSource(uri=gcs_source_uri)
input_config = vision.types.InputConfig(
gcs_source=gcs_source, mime_type=mimetype)
request = vision.types.AnnotateFileRequest(features=[feature], input_config=input_config)
print('Waiting for the ORC operation to finish.')
ocr_response = vision_client.batch_annotate_files(requests=[request])
print('OCR completed.')
在响应中,我希望在 ocr_response.responses[1...n].pages[1...n].blocks[1...n].bounding_box
中找到一个 vertices
的列表,但这个列表是空的。相反,有一个 normalized_vertices
列表,它是 0 和 1 之间的规范化顶点。为什么会这样?为什么 vertices
结构是空的?
我正在关注 this 文章,那里的作者使用 vertices
,但我不明白为什么我没有得到它们。
为了将它们转换为非规范化形式,我将规范化的顶点乘以高度和宽度,但结果很糟糕,盒子没有很好地定位。
要将 Normalized Vertex 转换为 Vertex,您应该将 NormalizedVertex 的 x 字段乘以宽度值以获得 Vertex 的 x 字段,并将 NormalizedVertex 的 y 字段乘以高度值以获得顶点.
reason 为什么你得到 Normalized Vertex,而 Medium 文章的作者得到 Vertex 是因为 TEXT_DETECTION 和 DOCUMENT_TEXT_DETECTION 模型自 5 月 15 日以来已升级到较新的版本, 2020, medium文章写于2018年12月25日
要对结果使用遗留模型,您必须在要素对象的模型字段中指定 "builtin/legacy_20190601" 以获取旧模型结果。
但是 Google 的文档提到,2020 年 11 月 15 日之后将不再提供旧型号。