python - 向 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)
解决方案
即使已经很晚了,我希望这对其他人有帮助。
基于此,您可以执行以下操作:
image = vision.types.Image(content=content)
context = vision.types.ImageContext(language_hints=['ko'])
response = client.text_detection(image=image, image_context=context)
请注意,该language_hints
参数需要一个列表。
推荐阅读
- autodesk-forge - Autodesk Forge 查看器 TypeScript 绑定中缺少 BubbleNode.getDefaultGeometry
- java - ClassCastException:class by.AppInit 不能转换为类 javax.servlet.ServletContainerInitializer
- amazon-web-services - 如何增加 ECS FARGATE 容器存储
- visual-studio-code - vscode中的lisp调试?
- typescript - 打字稿:如何在 Array.map 函数参数中添加索引签名
- javascript - 如果选择 1 具有 jquery 的值,则更改选择 2 的选项值
- java - JAVA 单行字符进度条在 NetBeans 输出窗口中有效但在 CMD 中无效
- google-apps-script - 从 G Suite Makrketplace 安装插件后,onInstall 触发器不会运行
- azure - 部署到 Azure 时如何使用应用程序设置而不是 screts.json
- python - 如何在matplotlib中获取每个条的高度(以像素为单位)