I have uploaded images using php on S3, now i want to compare/match given image in my S3 collection, I googled but not getting answer, if it is possible to use AWS face rekognition using PHP to search in S3 collection.
3 Answers
Use the compareFaces APi to compare faces present in two images stored in S3. Keep one image as source and pass the target images in iteration.
API:
<?php
require 'vendor/autoload.php';
use Aws\Rekognition\RekognitionClient;
$options = [
'region' => 'us-east-1',
'version' => '2016-06-27',
];
$client = new RekognitionClient($options);
$result = $client->compareFaces([
'SimilarityThreshold' => <float>,
'SourceImage' => [
'Bytes' => <string || resource || Psr\Http\Message\StreamInterface>,
'S3Object' => [
'Bucket' => '<string>',
'Name' => '<string>',
'Version' => '<string>',
],
],
'TargetImage' => [
'Bytes' => <string || resource || Psr\Http\Message\StreamInterface>,
'S3Object' => [
'Bucket' => '<string>',
'Name' => '<string>',
'Version' => '<string>',
],
],
]);
?>
If you want to search within a collection(assuming you have already created one using CreateCollection API and have already indexed faces in it), then you can use the searchFacesByImage API. Just provide the target collection-id(which has multiple images indexed in it) along with the s3-location of the source image. The response will contain all the faces that matches, ordered by similarity score.
API:
$result = $client->searchFacesByImage([
'CollectionId' => '<string>',
'FaceMatchThreshold' => <float>,
'Image' => [
'Bytes' => <string || resource || Psr\Http\Message\StreamInterface>,
'S3Object' => [
'Bucket' => '<string>',
'Name' => '<string>',
'Version' => '<string>',
],
],
'MaxFaces' => <integer>,
]);

- 2,793
- 11
- 28
@Madhukar's answer is correct, however you need one more step to search the s3 bucket. You need to index the faces in the bucket like so:
$result = $rekog->indexFaces([
'CollectionId' => '<string>', // REQUIRED
'ExternalImageId' => <string>, //This is important to know what image the face is in (I use the s3 key)
'Image' => [
'S3Object' => [
'Bucket' => '<string>',
'Name' => <string>,
],
],
]);
You will need to do this for every image in the collection

- 113
- 9
Thanks @Madhukar, your suggestion worked for me to compare 2 images from S3 whereas to search in collection I had to add Chris's suggestion. Thank you @chris. Only my issue was I am doing in laravel so I had to do in Laravel style but core is all your suggestion. Thanks again both of you. If someone want laravel codding let me know, If I could help.

- 17
- 5
$response = $s3->putObject(array( 'CollectionId' => 'visitor-collection', 'Bucket' => 's3-visitor', 'Key' => 'visitors/'.$input['imageId'], 'SourceFile' => public_path('images/attachments/').$input['imageId'], )); $s3Id = $response['ObjectURL']; return $s3Id;
– user3560746 Oct 16 '17 at 14:11