Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DataSolveProblems/aca9f1a4a084f93ace6ffaed632c357f to your computer and use it in GitHub Desktop.
Save DataSolveProblems/aca9f1a4a084f93ace6ffaed632c357f to your computer and use it in GitHub Desktop.
import os
import io
from google.cloud import vision
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'ServiceAccountToken.json'
client = vision.ImageAnnotatorClient()
file_name = 'sunset.jpg'
image_path = f'.\Images\{file_name}'
with io.open(image_path, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.image_properties(image=image).image_properties_annotation
dominant_colors = response.dominant_colors
for color in dominant_colors.colors:
print('pixel fraction :{0}'.format(color.pixel_fraction))
print('score: {0}'.format(color.score))
print('\tred: {0}'.format(color.color.red))
print('\tgreen: {0}'.format(color.color.green))
print('\tblue: {0}'.format(color.color.blue))
print('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment