Google Vision API Setup Python Tutorial - Updated for 2019

Publicado em: 20 Julho 2017
no canal de: 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)))


Nesta página do site você pode assistir ao vídeo on-line Google Vision API Setup Python Tutorial - Updated for 2019 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Victor Yang 20 Julho 2017, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 15,949 vezes e gostou 86 espectadores. Boa visualização!