httpwwwbethedevcom
324329524619168
Loading...

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

  1. Hello, I have used your code and it is very helpful for me thanks. I want to compare one image with lots of other images so please suggest me a way to done this. It is very critical part for my project. I have checked this link https://docs.aws.amazon.com/rekognition/latest/dg/faces-comparefaces.html but It cannot give PHP code. So please suggest me PHP code.

    ReplyDelete
  2. You can use 'Collection' feature here. Create a new "collection" in AWS Rek and Insert your face into that collection using "indexFaces" then you can search faces using "Search Face by Image". That's all. if you have doubt don't hesitate to ping me.

    ReplyDelete
  3. Hello.
    I am using your given code. Thank you for your great work.
    Issues Found as follows:
    1. Line Number 29,30 & 31 are ; missing at the end of each line.
    2. After updating the above code I am seeing the following output.
    [
    {
    "Similarity": 98.67130279541016,
    "Face": {
    "BoundingBox": {
    "Width": 0.6604781746864319,
    "Height": 0.5646838545799255,
    "Left": 0.11811203509569168,
    "Top": 0.09955057501792908
    },
    "Confidence": 99.99998474121094,

    My Question is How I can extract only "Similarity" value?
    There is NO FaceMatches as you shown in the output.

    ReplyDelete
  4. //Calling Compare Face function
    $compareFaceResults = $rekognitionClient->compareFaces([
    'SimilarityThreshold' => 80,
    'SourceImage' => [
    'Bytes' => file_get_contents($stored_face)
    ],
    'TargetImage' => [
    'Bytes' => file_get_contents($current_face)
    ],
    ]);
    $FaceMatchesResult = $compareFaceResults['FaceMatches'];
    $SimilarityResult = $FaceMatchesResult[0]['Similarity'];
    echo json_encode($SimilarityResult);

    ReplyDelete
  5. @ MyKodeZone Can you share your response to check ?

    ReplyDelete
  6. WordPress is a versatile platform and is used for different types of websites. If you’re planning to have a complex website or make it a business venture, then finding the right Wordpress Developer is important. You should go for a person who has extensive WordPress experience, is well-versed with the latest version and is familiar with the best practices.

    ReplyDelete

emo-but-icon

Home item

Popular Posts

Random Posts