我想将图像的base64编码的字符串发送给Google的Vision API,但我似乎不知道该怎么做。我应该怎么做?
我的代码
@staticmethod
def get_text_detection_from_img(img_name):
credentials = service_account.Credentials.from_service_account_file("key.json")
client = vision.ImageAnnotatorClient(credentials=credentials)
with open(img_name, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
response = client.annotate_image(
{"image": {"content": encoded_string}, "features":
[{'type': vision.enums.Feature.Type.TEXT_DETECTION}]})
print(response)