【问题标题】:AWS Rekognition detect label Invalid image encoding errorAWS Rekognition 检测标签无效的图像编码错误
【发布时间】:2018-08-23 22:05:00
【问题描述】:

我正在使用 boto3 调用识别的检测标签方法,该方法将图像(以 base64 编码字节的形式)作为输入。但是我不断收到 InvalidImageFormatException ,我不明白为什么。我已阅读文档并查看了一些示例,但我真的无法弄清楚为什么会收到此错误。

以下是我的代码以及到目前为止我尝试过的内容

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

【问题讨论】:

    标签: python boto3 amazon-rekognition


    【解决方案1】:

    弄清楚了,该方法实际上需要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})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-29
      • 1970-01-01
      • 2011-02-25
      • 2020-09-29
      • 2018-03-14
      • 1970-01-01
      相关资源
      最近更新 更多