Google Vision API Setup Python Tutorial - Updated for 2019
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/dashboard
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/en/latest/gcloud-auth.html
3. Log into your google account:
gcloud auth login
More info on authentication:
https://cloud.google.com/vision/docs/auth
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/python-client-migration
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)))
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Google Vision API Setup Python Tutorial - Updated for 2019», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.