Where to use Language hints in google-vision text-detection api?

故事扮演 提交于 2020-08-27 21:26:11

问题


So I know that google-vision api supports multiple language for text-detection. And by using the code below I can detect english language from image. But according to google I can use the parameter language hints to detect other languages. So where exactly am I suppose to put this parameter in the code below?

def detect_text(path):
    """Detects text in the file."""
    from google.cloud import vision
    imageContext = 'bn'
    client = vision.ImageAnnotatorClient(imageContext)

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


detect_text('Outline-of-the-Bangladesh-license-plates_Q320.jpg')



回答1:


Like this:

response = client.text_detection(
    image=image,
    image_context={"language_hints": ["bn"]},  # Bengali
)

See "ImageContext" for more details.



来源:https://stackoverflow.com/questions/55364164/where-to-use-language-hints-in-google-vision-text-detection-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!