Google Vision API Setup Python Tutorial - Updated for 2019

Опубликовано: 20 Июль 2017
на канале: 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)))


На этой странице сайта вы можете посмотреть видео онлайн Google Vision API Setup Python Tutorial - Updated for 2019 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Victor Yang 20 Июль 2017, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 15,949 раз и оно понравилось 86 зрителям. Приятного просмотра!