首页 > 解决方案 > 向 Google Cloud Vision 添加语言提示

问题描述

如何将语言提示添加到我的谷歌云视觉 python 代码中。从https://cloud.google.com/vision/docs/languages我知道它是受支持的,但我不知道如何在代码中实现它。

from google.cloud import vision
client = vision.ImageAnnotatorClient()

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

image = vision.types.Image(content=content)

response = client.text_detection(image=image)
texts = response.text_annotations
print('Texts:')

for text in texts:
    print('\n"{}"'.format(text.description))

    vertices = (['({},{})'.format(vertex.x, vertex.y)
                for vertex in text.bounding_poly.vertices])

    print('bounds: {}'.format(','.join(vertices)))

我想我必须这样做:

context = imageContext.setLanguageHints("ko")
response = client.text_detection(image=image, context=context)

标签: pythongoogle-vision

解决方案


即使已经很晚了,我希望这对其他人有帮助。

基于,您可以执行以下操作:

image = vision.types.Image(content=content)
context = vision.types.ImageContext(language_hints=['ko'])
response = client.text_detection(image=image, image_context=context)

请注意,该language_hints参数需要一个列表。


推荐阅读