本文介绍了在 google-vision text-detection api 中在哪里使用语言提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我知道 google-vision api 支持多种语言进行文本检测.通过使用下面的代码,我可以从图像中检测英语.但是根据谷歌,我可以使用参数语言提示来检测其他语言.那么我想在下面的代码中到底把这个参数放在哪里?
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')
推荐答案
像这样:
response = client.text_detection(
image=image,
image_context={"language_hints": ["bn"]}, # Bengali
)
参见 ImageContext" 了解更多详情.
See "ImageContext" for more details.
这篇关于在 google-vision text-detection api 中在哪里使用语言提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!