Python AWS重新识别检测标签无效图像编码错误
我使用boto3调用recognition的detect label方法,该方法将图像(以base64编码字节的形式)作为输入。然而,我不断地变得异常,我不明白为什么。我已经阅读了文档并查看了一些示例,但是我真的不明白为什么我会收到这个错误 下面是我的代码和我迄今为止尝试的内容Python AWS重新识别检测标签无效图像编码错误,python,boto3,amazon-rekognition,Python,Boto3,Amazon Rekognition,我使用boto3调用recognition的detect label方法,该方法将图像(以base64编码字节的形式)作为输入。然而,我不断地变得异常,我不明白为什么。我已经阅读了文档并查看了一些示例,但是我真的不明白为什么我会收到这个错误 下面是我的代码和我迄今为止尝试的内容 self.rekog_client = boto3.client('rekognition', 'us-east-1') with open('abc100.jpg', "rb") as cf: base64_i
self.rekog_client = boto3.client('rekognition', 'us-east-1')
with open('abc100.jpg', "rb") as cf:
base64_image=base64.b64encode(cf.read()).decode("ascii")
#also tried this) ==> base64_image=base64.b64encode(cf.read())
resp = self.rekog_client.detect_labels(Image={'Bytes': base64_image})
输出/异常:
botocore.errorfactory.InvalidImageFormatException: An error occurred(InvalidImageFormatException) when calling the DetectLabels operation: Invalid image encoding
计算出来,该方法实际上需要base64编码的二进制数据,而文档中并没有指定这些数据,文档只是说base64编码的字节
self.rekog_client = boto3.client('rekognition', 'us-east-1')
with open('cat_pic600.jpg', "rb") as cf:
base64_image=base64.b64encode(cf.read())
base_64_binary = base64.decodebytes(base64_image)
resp = self.rekog_client.detect_labels(Image={'Bytes': base_64_binary})