from google.cloud.vision import types
def analyze_image(path):
«»»Detect dominant colors in the file.»»»
client = vision.ImageAnnotatorClient()
# with io.open(path, ‘rb’) as image_file:
# content = image_file.read()
content = path
image = types.Image(content=content)
response = client.image_properties(image=image)
props = response.image_properties_annotation
print(‘Dominant colors:’)
for color in props.dominant_colors.colors:
print(‘fraction: %f’ % color.pixel_fraction)
print(‘tr: %f, g: %f, b: %f’ % (color.color.red, color.color.green, color.color.blue))
return response
if __name__ == ‘__main__’:
path = ‘resources/wakeupcat.jpg’
analyze_image(path)