是否可以在Python中脱机使用Google vision API?

时间:2018-02-09 13:22:15

标签: python google-api google-api-client google-vision

我有一个使用Google vision API的简单Python应用程序。如何使其脱机工作?我搜索了很多,但找不到任何有用的东西。这个question 是关于Android应用程序的,似乎对于这种情况,答案是肯定的。这是我的代码:

from google.cloud import vision
from google.cloud.vision import types
from google.oauth2 import service_account
credentials=service_account.Credentials.from_service_account_file('key.json')
client = vision.ImageAnnotatorClient(credentials=credentials)
with io.open('my_figure.jpg', 'rb') as image_file:
     content = image_file.read()
image_context = types.ImageContext(language_hints =["en"])
image = types.Image(content=content)
response = client.text_detection(image=image, image_context=image_context)
texts = response.text_annotations
for text in texts:
  print('\n"{}"'.format(text.description))

0 个答案:

没有答案