Search code examples
amazon-web-servicesamazon-s3amazon-dynamodbamazon-rekognition

Where condition in dynamodb rekognition.search_faces_by_image function


Hi I am getting database data in this code like this

response = rekognition.search_faces_by_image(
                        CollectionId='athlete_collection',
                        Image={'Bytes': image_crop_binary}
                    )

I have a column named event in athlete_collection so I want to put a condition that just get data where event = 'newevent'


Solution

  • here you are going wrong concept-wise , because you are trying to filter athlete_collection which is just a Rekognition collection which just contains facial landmarks data of stored faces and face-ids corresponding to that faces , then you can use those face-ids to retrieve corresponding data like names,address,etc if and only if you stored such details in a database while indexing those faces in the collection , if in your use case event name is stored in database , so you have to filter data while retrieving results from database corresponding to results obtained from search_faces_by_image API

    you can do this by following below example:

    response = rekognition.search_faces_by_image(
        CollectionId='collection_name',
        Image={'Bytes':image_crop_binary}
        )
    
    if len(response['FaceMatches']) > 0:
        # Return results
        for match in response['FaceMatches']:
    
            face = dynamodb.get_item(
            TableName='table_name',               
            Key={'RekognitionId': {'S': match['Face']['FaceId']}}
            )
    
    
        if 'Item' in face:
            event = face['Item']['event_name']['S']
            full = face['Item']['full_name']['S']
    
        if(event=='newevent'):
            #your code goes here , i.e what you want to do if event=="newevent"