Skip to content

71. Amazon Web Services (AWS) Rekognition

Note

The below information is extensively based in information taken from the PowerShell® Notes for Professionals book. I plan to extend this information based on my day to day usage of the language.

Amazon Rekognition is a service that makes it easy to add image analysis to your applications. With Rekognition, you can detect objects, scenes, and faces in images. You can also search and compare faces. Rekognition’s API enables you to quickly add sophisticated deep learning-based visual search and image classification to your applications.

71.1: Detect Image Labels with AWS Rekognition

1
2
3
4
5
6
7
8
$BucketName = 'trevorrekognition'
$FileName = 'kitchen.jpg'

New-S3Bucket -BucketName $BucketName
Write-S3Object -BucketName $BucketName -File $FileName
$REKResult = Find-REKLabel -Region us-east- 1 - ImageBucket $BucketName -ImageName $FileName

$REKResult.Labels

After running the script above, you should have results printed in your PowerShell host that look something similar to the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
RESULTS:
Confidence Name
---------- ----
86.87605 Indoors
86.87605 Interior Design
86.87605 Room
77.4853 Kitchen
77.25354 Housing
77.25354 Loft
66.77325 Appliance
66.77325 Oven

Using the AWS PowerShell module in conjunction with the AWS Rekognition service, you can detect labels in an image, such as identifying objects in a room, attributes about photos you took, and the corresponding confidence level that AWS Rekognition has for each of those attributes. The Find-REKLabel command is the one that enables you to invoke a search for these attributes / labels. While you can provide image content as a byte array during the API call, a better method is to upload your image files to an AWS S3 Bucket, and then point the Rekognition service over to the S3 Objects that you want to analyze. The example above shows how to accomplish this.

71.2: Compare Facial Similarity with AWS Rekognition

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
$BucketName = 'trevorrekognition'

### Create a new AWS S3 Bucket
New-S3Bucket -BucketName $BucketName

### Upload two different photos of myself to AWS S3 Bucket
Write-S3Object -BucketName $BucketName -File myphoto1.jpg
Write-S3Object -BucketName $BucketName -File myphoto2.jpg

### Perform a facial comparison between the two photos with AWS Rekognition
$Comparison = @{
  SourceImageBucket = $BucketName
  TargetImageBucket = $BucketName
  SourceImageName = 'myphoto1.jpg'
  TargetImageName = 'myphoto2.jpg'
  Region = 'us-east-1'
}

$Result = Compare-REKFace @Comparison
$Result.FaceMatches

The example script provided above should give you results similar to the following:

1
2
3
Face Similarity
---- ----------
Amazon.Rekognition.Model.ComparedFace 90

The AWS Rekognition service enables you to perform a facial comparison between two photos. Using this service is quite straightforward. Simply upload two image files, that you want to compare, to an AWS S3 Bucket. Then, invoke the Compare-REKFace command, similar to the example provided above. Of course, you'll need to provide your own, globally-unique S3 Bucket name and file names.