简体   繁体   English

AWS:在 DeepLens 设备上运行 Rekognition

[英]AWS : Running Rekognition on DeepLens device

I am creating a DeepLens project to recognise people, when one of select group of people are scanned by the camera.当相机扫描一群人时,我正在创建一个深层项目来识别人们。

The project uses a lambda, which processes the images and triggers the 'rekognition' aws api.该项目使用 lambda,它处理图像并触发“rekognition”aws api。

On AWS lambda console ( which has 1.8.9 boto version ), I get following issue when I try to call an AWS python API:在 AWS lambda 控制台(具有 1.8.9 boto 版本)上,当我尝试调用 AWS python API 时遇到以下问题:

Note: img_str is a byte array注意: 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 } )

First error : sendall() argument 1 must be string or buffer, not dict第一个错误:sendall() 参数 1 必须是字符串或缓冲区,而不是字典

Reason in my understanding : { "Bytes": image } is a Json and NOT a string我理解的原因:{ "Bytes": image } 是一个 Json 而不是一个字符串

My Solution : Make the json a string ( not sure whether I can concatenate img_str ( a byte array )我的解决方案:使 json 成为一个字符串(不确定我是否可以连接 img_str(一个字节数组)

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

Now error : Error in face detection lambda: 'ascii' codec can't decode byte 0xff in position 52: ordinal not in range(128)现在错误:面部检测 lambda 错误:'ascii' 编解码器无法解码位置 52 中的字节 0xff:序号不在范围内(128)

Question How do I concatenate a byte array (img_str) with strings without losing the array?问题如何在不丢失数组的情况下将字节数组 (img_str) 与字符串连接起来?

Can i convert image variable to string WITHOUT getting the can't decode byte 0xff exception?我可以将图像变量转换为字符串而不会出现无法解码字节 0xff异常吗? or要么

Can we do something else to overcome this issue?我们可以做点别的事情来克服这个问题吗?

Thanks in advance guys !!提前谢谢大家!

I did something similar and this piece of code worked for me:我做了类似的事情,这段代码对我有用:

    # 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})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM