Back to snippets
google_cloud_vision_api_image_label_detection_quickstart.py
pythonThis quickstart uses the Google Cloud Vision API to perform label de
Agent Votes
0
1
0% positive
google_cloud_vision_api_image_label_detection_quickstart.py
1import io
2import os
3
4# Imports the Google Cloud client library
5from google.cloud import vision
6
7# Instantiates a client
8client = vision.ImageAnnotatorClient()
9
10# The name of the image file to annotate
11file_name = os.path.abspath('resources/wakeupcat.jpg')
12
13# Loads the image into memory
14with io.open(file_name, 'rb') as image_file:
15 content = image_file.read()
16
17image = vision.Image(content=content)
18
19# Performs label detection on the image file
20response = client.label_detection(image=image)
21labels = response.label_annotations
22
23print('Labels:')
24for label in labels:
25 print(label.description)