3
votes

I am using Python Client for Google Cloud Vision API, basically same code as in documentation 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}],
... })

problem is that response doesn't have field "annotations" (as it is documentation) but based on documentation has field for each "type". so when I try to get response.face_annotations I get and basically I don't know how to extract result from Vision API from response (AnnotateImageResponse) to get something like json/dictionary like data. version of google-cloud-vision is 0.25.1 and it was installed as full google-cloud library (pip install google-cloud). I think today is not my day I appreciate any clarification / help

2

2 Answers

1
votes

Hm. It is a bit tricky, but the API is pretty great overall. You can actually directly call the face detection interface, and it'll spit back exactly what you want - a dictionary with all the info.

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 
-1
votes