Reputation: 11
I am integrating my camera with Google cloud vision API so that I can count the total number of people in a room. But the API is returning only 10 responses.
In order to get more responses I added the field max_results
in features
. After adding the max_results
field it is returning more than 10 responses, but then I get the problem that it is only accepting an image with a 'URI' and I am unable to give it an image present on my system. It is only accepting images present on the internet with an image address like in the piece of code below. Now how can I specify an image present on my system instead of giving URI?
My python code for taking image and features:
response = client.annotate_image({'image': {'source': {'image_uri':'http://im.rediff.com/news/2016/jan/26republic-day1.jpg'}}, 'features': [{'type': vision.enums.Feature.Type.FACE_DETECTION,'max_results':40}],})
Upvotes: 1
Views: 1612
Reputation: 7058
Working snippet:
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types
# Instantiates a client
client = vision.ImageAnnotatorClient()
# The name of the image file to annotate
file_name = os.path.join(
os.path.dirname(__file__),
'face.jpeg')
# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image = types.Image(content=content)
response = client.annotate_image({'image': image, 'features': [{'type': vision.enums.Feature.Type.FACE_DETECTION,'max_results':40}],})
print response
# Print joy likelihood
for face in response.face_annotations:
print(face.joy_likelihood)
Basically, pass the image and not just the filename
Upvotes: 0