Steps:
https://console.cloud.google.com/home/dashboard
1. Create a project and enable vision api
Get API key and service account key
go to C:\Python27\Scripts
2. Install following:
pip install --upgrade google-api-python-client
pip install --upgrade google-cloud-vision
pip install --upgrade google-cloud
install gcloud sdk for Authentication error fixes.
https://cloud.google.com/sdk/
More information at http://gcloud-python.readthedocs.io/en/latest/gcloud-auth.html
3. Go to the Cloud_SDK folder and run:
gcloud auth login
More info on authentication:
https://cloud.google.com/vision/docs/auth
4. Run the following code:
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
# Instantiates a client (Change the line below******)
vision_client = vision.Client('your_account_key.json')
# The name of the image file to annotate (Change the line below 'image_path.jpg' ******)
file_name = os.path.join(
os.path.dirname(__file__),
'image_path.jpg') # Your image path from current directory
# 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)
Source: https://cloud.google.com/vision/docs/detecting-labels#vision-label-detection-python