gpt4 book ai didi

python - AWS Rekognition 检测标签无效图像编码错误

转载 作者:行者123 更新时间:2023-12-04 00:30:27 25 4
gpt4 key购买 nike

我正在使用 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

最佳答案

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

关于python - AWS Rekognition 检测标签无效图像编码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51959646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com