在谷歌视觉文字检测API中,何处使用语言提示?

7

我知道Google Vision API支持多种语言的文本检测。通过以下代码,我可以从图像中检测出英语语言。但是根据Google的说法,我可以使用语言提示参数来检测其他语言。那么我应该在以下代码中的哪里放置此参数呢?

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个回答

11

就像这样:

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

请参阅"ImageContext"以获取更多详细信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接