我有一个使用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))