0

how can I add languageHints to my google cloud vision python code. From https://cloud.google.com/vision/docs/languages I know that it is supported but I do not know how to implement it into the code.

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)))

I think I have to do it like this:

context = imageContext.setLanguageHints("ko")
response = client.text_detection(image=image, context=context)
seeberg
  • 99
  • 1
  • 11

1 Answers1

0

Even though it's late, I hope this help's another people.

Based on this, you could do something like this:

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

Note that the language_hints parameter expects a list.

fsmiamoto
  • 1
  • 1