【问题标题】:AWS : Running Rekognition on DeepLens deviceAWS:在 DeepLens 设备上运行 Rekognition
【发布时间】:2021-02-14 15:12:39
【问题描述】:

我正在创建一个 DeepLens 项目来识别人,当相机扫描选定的一组人时。

该项目使用 lambda,它处理图像并触发“rekognition”aws api。

在 AWS lambda 控制台(具有 1.8.9 boto 版本)上,当我尝试调用 AWS python API 时遇到以下问题:

注意:img_str 是一个字节数组

img_str = cv2.imencode('.jpg', frame)[1].tostring()
image = { 'Bytes': img_str }
response = rekognition.search_faces_by_image(CollectionId = 'TestingCollection', Image = { "Bytes" : image } )

第一个错误:sendall() 参数 1 必须是字符串或缓冲区,而不是 dict

我理解的原因 : { "Bytes" : image } 是 Json 而不是字符串

我的解决方案:将 json 设为字符串(不确定是否可以连接 img_str(字节数组)

image = '{ "Bytes" :' + img_str + '}'
response = rekognition.search_faces_by_image(CollectionId = 'TestingCollection', Image = { "Bytes" : image } )

现在错误:面部检测 lambda 错误:“ascii”编解码器无法解码位置 52 的字节 0xff:序数不在范围内 (128)

问题 如何在不丢失数组的情况下将字节数组 (img_str) 与字符串连接起来?

我可以将 image 变量转换为字符串,而不会出现 无法解码字节 0xff 异常吗?或

我们可以采取其他措施来解决这个问题吗?

提前谢谢大家!!

【问题讨论】:

    标签: python aws-lambda boto3 amazon-rekognition aws-deeplens


    【解决方案1】:

    我做了类似的事情,这段代码对我有用:

        # img is an image object (numpy array)
        success, img = cv2.imencode('.jpg', img)
        image= img.tobytes()
        response=client.search_faces_by_image(CollectionId='TestingCollection',
                                            Image={'Bytes':image})
    

    【讨论】:

      猜你喜欢
      • 2015-10-16
      • 2012-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多