Google Vision API Setup Python Tutorial - Updated for 2019

Published: 20 July 2017
on channel: Victor Yang
15,949
86

The following are the exact steps I took from start to end result.
Steps:

1. Create a project and enable vision api
https://console.cloud.google.com/home...
Get API key and service account key

2. Install following:

pip install --upgrade google-api-python-client
pip install --upgrade google-cloud-vision
pip install --upgrade google-cloud
pip install gcloud

install gcloud sdk for Authentication error fixes:
https://cloud.google.com/sdk/
More information at http://gcloud-python.readthedocs.io/e...

3. Log into your google account:
gcloud auth login

More info on authentication:
https://cloud.google.com/vision/docs/...

4. Run the following code (*UPDATED*):
#edited 10/18/19
I noticed many people had "AttributeError: module 'google.cloud.vision' has no attribute 'Client' " issue. The reason is google made updates to the google-cloud-vision module.
https://cloud.google.com/vision/docs/...

Updated code as of 10/18/19
-----------------------------------------------------------------------------------------------------------------------------------------------------------
import io
import os
Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types

Instantiates a client
#EDIT the line below
credential_path = r"your_account_key.json"
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credential_path

client = vision.ImageAnnotatorClient()

The name of the image file to annotate
#EDIT the line below
file_name = os.path.abspath('your_image_file.jpg')

Loads the image into memory
with io.open(file_name, 'rb') as image_file:
content = image_file.read()

image = types.Image(content=content)

Performs label detection on the image file
response = client.label_detection(image=image)
labels = response.label_annotations

print('Labels:')
for label in labels:
print(label.description)

Performs text detection on the image file_name
response = client.text_detection(image=image)
texts = response.text_annotations
print('\nTexts:')

for text in texts:
print('\n"{}"'.format(text.description))
vertices = (['({},{})'.format(vertex.x, vertex.y)
for vertex in text.bounding_poly.vertices])
print('bounds: {}'.format(','.join(vertices)))


On this page of the site you can watch the video online Google Vision API Setup Python Tutorial - Updated for 2019 with a duration of hours minute second in good quality, which was uploaded by the user Victor Yang 20 July 2017, share the link with friends and acquaintances, this video has already been watched 15,949 times on youtube and it was liked by 86 viewers. Enjoy your viewing!