-
-
Save pegasuskim/d91719fab00f207a37138d6a48647caa to your computer and use it in GitHub Desktop.
google cloud platform (vision api)
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 io | |
import os | |
# export GOOGLE_APPLICATION_CREDENTIALS=/home/oops/github/gcloud/GCP-ML-8492a87b7f32.json | |
# Imports the Google Cloud client library | |
from google.cloud import vision | |
# Instantiates a client | |
vision_client = vision.Client() | |
# The name of the image file to annotate | |
file_name = os.path.join( | |
os.path.dirname(__file__), | |
'test.jpg') | |
# Loads the image into memory | |
with io.open(file_name, 'rb') as image_file: | |
content = image_file.read() | |
image = vision_client.image( | |
content=content) | |
# Performs label detection on the image file | |
labels = image.detect_labels() | |
print('Labels:') | |
for label in labels: | |
print(label.description) | |
faces = image.detect_faces() | |
print('Faces:') | |
for face in faces: | |
print('anger: {}'.format(face.emotions.anger)) | |
print('joy: {}'.format(face.emotions.joy)) | |
print('surprise: {}'.format(face.emotions.surprise)) | |
vertices = (['({},{})'.format(bound.x_coordinate, bound.y_coordinate) | |
for bound in face.bounds.vertices]) | |
print('face bounds: {}'.format(','.join(vertices))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment