How to use AWS Rekognition to Compare Face in PHP | Face Recognition API

Shows How to use the Aws\Rekognition\RekognitionClient object to call the compare faces operations. Face Recognition API

AWS Rekognition to Compare Face in PHP

Use Recognition Client
require 'vendor/aws/aws-autoloader.php';
use Aws\Rekognition\RekognitionClient;

Credentials for access AWS Service code parameter
$credentials = new Aws\Credentials\Credentials('{AWS access key ID}', '{AWS secret access key}');

Get Rekognition Access

$rekognitionClient = RekognitionClient::factory(array(
'region' => "us-east-1",
'version' => 'latest',
'credentials' => $credentials

Calling Compare Face function
$compareFaceResults= $rekognitionClient->compareFaces([
'SimilarityThreshold' => 80,
'SourceImage' => [
'Bytes' => file_get_contents("SourceImage.jpg")
'TargetImage' => [
'Bytes' => file_get_contents("TargetImage.jpg")

Response to JSON Data
$FaceMatchesResult = $compareFaceResults['FaceMatches'];
$SimilarityResult = $FaceMatchesResult['Similarity'] //Here You will get similarity
$sourceImageFace = $compareFaceResults['SourceImageFace']
$sourceConfidence = $sourceImageFace['Confidence'] // //Here You will get confidence of the picture

Full Source Code :

Note: AWS Results Example:-

If this code was helpful, I would love to hear from you or If you have any questions please post your comments below.

Thank you!
Rekognition 6101165258861166923

Post a Comment Default Comments Disqus Comments


Home item

Follow by Email

Popular Posts

Random Posts