How can I match multiple faces at a time using AWS Rekognition?

Viewed 25

I am matching selfie face with album photos using Face Rekognition PHP SDK.

for that, I am go through the user selfies loop and check one by one. and it's taking around 15 minutes to get result.

Here, the my code snippet that I performed.

<?php

foreach ( $user_bio_selfies as $selfi ) {
    $selfi_path = $user_selfi_path . $selfi['image'];
    if ( file_exists( $selfi_path ) ) {
        $binary_target_face_image = file_get_contents($selfi_path);

        try {
            $compareFaces = array(
                'QualityFilter' => 'HIGH',
                'SimilarityThreshold' => 70,
                'SourceImage' => array(
                    'Bytes' => $binary_source_face_image,
                ),
                'TargetImage' => array(
                    'Bytes' => $binary_target_face_image,
                ),
            );
            $result = $this->client->compareFaces($compareFaces);
            $response = $result->toArray();
            if ( !empty( $response['FaceMatches'] ) ) {
                $matched_face = number_format($response['FaceMatches'][0]['Face']['Confidence'],  2, '.', '');
                
                if ( $matched_face >= 30 ) {
                    $matched_images[] = array(
                        'image' => base_url(USER_IMAGE_SITE_PATH) . $selfi['image'],
                        'confidence' => $matched_face,
                    );
                }
            }
        } catch (Exception $e) { }
    }
}

is there any way to match selfies with chuck of images at a time in AWS Rekognition?

1 Answers

The compareFaces() method "compares a face in the source input image with each of the 100 largest faces detected in the target input image."

The slowest part of this operation would be uploading the images to compare.

It would be faster to create a Face Collection where you provide multiple images to create a 'collection' of faces. Then, you can use searchFacesByImage():

For a given input image, first detects the largest face in the image, and then searches the specified collection for matching faces. The operation compares the features of the input face with faces in the specified collection.

Thus, you only need to provide one image and it will compare that face against the faces already stored in a collection.

I recommend watching some AWS Reinvent videos to learn about Rekognition:

Related