Showing posts with label aws. Show all posts
Showing posts with label aws. Show all posts

Wednesday, January 29, 2020

handy aws amazon rekognition snippets

These are handy amazon rekognision snippets. Make sure you have loaded the aws sdk from amazon for php

I have developed such applications and utilized these stuffs in php and python. Its pretty straight forward.

Snippets below!

Create collection

$result = $client->createCollection([
    'CollectionId' => 'mycollectionid',
]);

Results

[
    'CollectionArn' => 'aws:rekognition:us-west-

2:13234342323:collection/mycollectionid',
    'StatusCode' => 200,
]

Index faces
$result = $client->indexFaces([
    'CollectionId' => 'myphotos',
    'DetectionAttributes' => [
    ],
    'ExternalImageId' => 'myphotoid',
    'Image' => [
        'S3Object' => [
            'Bucket' => 'mybucket',
            'Name' => 'myphoto',
        ],
    ],
]);


$result = $rekognitionClient->searchFacesByImage([
                    'CollectionId' => ''.$collection_id.'', // REQUIRED
                    'FaceMatchThreshold' => 25.0,
                    'Image' => [ // REQUIRED
                            'S3Object' => [
                                'Bucket' => 'facetracking',
                                'Name' => 'test.jpg',
                                'Key' => 'test.jpg',
                                'Version' => 'latest',
                            ],
                    ], 'MaxFaces' => 2,
                ]);



Video

$result = $client->startFaceDetection([
    'ClientRequestToken' => '',
    'FaceAttributes' => 'DEFAULT|ALL',
    'JobTag' => '',
    'NotificationChannel' => [
        'RoleArn' => '', // REQUIRED
        'SNSTopicArn' => '', // REQUIRED
    ],
    'Video' => [ // REQUIRED
        'S3Object' => [
            'Bucket' => '',
            'Name' => '',
            'Version' => '',
        ],
    ],
]);



$result = $client->getFaceDetection([
    'JobId' => '', // REQUIRED
    'MaxResults' => ,
    'NextToken' => '',
]);
GetFaceDetection returns an array of detected faces (Faces) sorted by the

time the faces were detected.



$result = $client->getFaceSearch([
    'JobId' => '', // REQUIRED
    'MaxResults' => ,
    'NextToken' => '',
    'SortBy' => 'INDEX|TIMESTAMP',
]);