【发布时间】:2018-01-15 15:59:31
【问题描述】:
我在我正在使用的一个小程序上使用适用于 Python 的 Google Cloud Vision API。该功能正在运行,我得到了 OCR 结果,但我需要先对这些结果进行格式化,然后才能使用它们。
这是函数:
# Call to OCR API
def detect_text_uri(uri):
"""Detects text in the file located in Google Cloud Storage or on the Web.
"""
client = vision.ImageAnnotatorClient()
image = types.Image()
image.source.image_uri = uri
response = client.text_detection(image=image)
texts = response.text_annotations
for text in texts:
textdescription = (" "+ text.description )
return textdescription
我特别需要将文本逐行切片,并在开头添加四个空格,最后添加一个换行符,但此时这仅适用于第一行,其余作为单行返回斑点。
我一直在查看官方文档,但并没有真正了解 API 响应的格式。
【问题讨论】:
标签: python google-cloud-platform google-cloud-vision