3

我正在为 Google Cloud Vision API 使用 Python 客户端,与文档http://google-cloud-python.readthedocs.io/en/latest/vision/中的代码基本相同

>>> from google.cloud import vision
>>> client = vision.ImageAnnotatorClient()
>>> response = client.annotate_image({
...   'image': {'source': {'image_uri': 'gs://my-test-bucket/image.jpg'}},
...   'features': [{'type': vision.enums.Feature.Type.FACE_DETECTOIN}],
... })

问题是响应没有字段“注释”(因为它是文档),但基于文档有每个“类型”的字段。因此,当我尝试获取 response.face_annotations 时,我得到了并且基本上我不知道如何从响应 (AnnotateImageResponse) 中提取 Vision API 的结果以获取类似 json/dictionary 之类的数据。google-cloud-vision 的版本是 0.25.1,它被安装为完整的 google-cloud 库(pip install google-cloud)。我认为今天不是我的日子我感谢任何澄清/帮助

4

2 回答 2

1

嗯。这有点棘手,但 API 总体上非常棒。您实际上可以直接调用人脸检测接口,它会准确地返回您想要的内容 - 包含所有信息的字典。

from google.cloud import vision
from google.cloud.vision import types

img = 'YOUR_IMAGE_URL'
client = vision.ImageAnnotatorClient()
image = vision.types.Image()
image.source.image_uri = img
faces = client.face_detection(image=image).face_annotations
print faces 
于 2018-10-16T21:31:22.073 回答
-1

很好的替代方法是使用 Python API Google 客户端,示例在这里https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/vision/api/label/label.py

于 2017-08-02T07:33:32.253 回答