Skip to content

Instantly share code, notes, and snippets.

@clintmjohnson
Created October 17, 2017 21:17
Show Gist options
  • Save clintmjohnson/1bd332e8975492288d30d217291db9db to your computer and use it in GitHub Desktop.
Save clintmjohnson/1bd332e8975492288d30d217291db9db to your computer and use it in GitHub Desktop.
This Python program connects to Google Vision API, to identify Images
def google_vision():
import io
import os
from google.cloud import vision
from google.cloud.vision import types
#https://cloud.google.com/vision/docs/auth
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "Path to Application default credentials JSON ADC"
client = vision.ImageAnnotatorClient()
file_name = 'Image File Name'
# 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.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
print(label.description)
if __name__ == '__main__':
google_vision()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment