2

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.

On AWS lambda console ( which has 1.8.9 boto version ), I get following issue when I try to call an AWS python API:

Note : img_str is a byte array

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

Reason in my understanding : { "Bytes" : image } is a Json and NOT a string

My Solution : Make the json a string ( not sure whether I can concatenate img_str ( a byte array )

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)

Question How do I concatenate a byte array (img_str) with strings without losing the array ?

Can i convert image variable to string WITHOUT getting the can't decode byte 0xff exception ? or

Can we do something else to overcome this issue ?

Thanks in advance guys !!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Deep
  • 673
  • 1
  • 10
  • 23

1 Answers1

1

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