Created
July 11, 2019 06:47
-
-
Save DataSolveProblems/aca9f1a4a084f93ace6ffaed632c357f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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