Google Vision API Setup Python Tutorial - Updated for 2019

Veröffentlicht am: 20 Juli 2017
auf dem Kanal: 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)))


Auf dieser Seite können Sie das Online-Video Google Vision API Setup Python Tutorial - Updated for 2019 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Victor Yang 20 Juli 2017 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 15,949 Mal angesehen und es wurde von 86 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!