Photostat - noun a still picture taken with a camera Source
In this challenge, we'll build an image analyzer that will rate the image using different criteria of your choosing by running the image through most of the Amazon Rekognition features.
An image passing the required criteria is deemed worthy of a profile picture and subsequently update social media profiles.
The following tools and accounts are required to complete these instructions.
Setup LambdaSharpTool and Deploy Skeleton Code
-
From any directory, install/update the λ# tool.
dotnet tool install -g MindTouch.LambdaSharp.Tool --version 0.4.0.4
-- Or if already installed, to update:
dotnet tool update -g MindTouch.LambdaSharp.Tool
-
Once installed/updated, the λ# CLI needs to be configured/updated.
dotnet lash config
-
Initialize/update deployment tier with the λ# runtime.
dotnet lash init --tier Sandbox
-
Clone this Repo.
-
From the root of the cloned repo, deploy the skeleton code. NOTE: This is the command to deploy any future changes.
cd Automated-Image-Workflow-Challenge/ dotnet lash deploy Fotostatur --tier Sandbox
See Setup LambdaSharp CLI & Runtime for detailed instructions and more info about the LambdaSharpTool. Note: LambdaSharp Contributors need to unset the
LAMBDASHARP
environment variable if you want to usedotnet lash
-
Find the
FotostaturPhotoBucket
bucket name in the CloudFormation outputs:Hint: From the AWS console navigate to
Cloudformation
>Sandbox-Fotostatur
>Resources
-
Test deployment by taking a picture or choosing an image to upload.
In the command below replace
SOURCE_IMAGE.JPG
andFOTO_STATUR_PHOTOBUCKET
for their respective names.From the directory where the image resides, run the command:
aws s3 cp SOURCE_IMAGE.JPG s3://FOTO_STATUR_PHOTOBUCKET/images/SOURCE_IMAGE.JPG
Note: It is being uploaded to an
images
path. -
Check the lambda function's CloudWatch logs to see if it was invoked with the S3 Upload. In the logs it should show the final score of 0.
-
From the directory where the image resides delete the image from S3.
rm s3://FOTO_STATUR_PHOTOBUCKET/images/SOURCE_IMAGE.JPG
Note: It is being deleted from an
images
path.
Note: While you could use the AWS console to upload an image, it's highly recommended for speedier development to use the AWS CLI to upload and remove images from S3.
Confidence score info/background and helper functions
A confidence score is a number between 0 and 100 that indicates the probability that a given prediction is correct.
Confidence scores are provided in most responses from Rekognition.
A helper function to add totals is provided. Use the following code snippet when needed:
AddTotals("criteria label", (float) 99.1234);
Where criteria label
is any string to identify the criteria, and the float
which is the confidence score.
Detect Objects and Scenes
In Fotostatur/ImageAnalyzer/Functions.cs
edit the DetectLabels
and ScoreLabels
methods.
- Detect the labels from the image uploaded.
- Score the results from detect labels using the
AddTotals
helper function to keep a running total.
Deploy with dotnet lash deploy Fotostatur --tier Sandbox
Test your code by using the CLI commands above to deploy, upload and remove images from S3.
Use CloudWatch to see the final score change based on criteria added.
Detect Text
In Fotostatur/ImageAnalyzer/Functions.cs
edit the DetectText
and ScoreText
methods.
- Detect any text from the image uploaded.
- Score the results from detect text using the
AddTotals
helper function to keep a running total.
Deploy with dotnet lash deploy Fotostatur --tier Sandbox
Test your code by using the CLI commands above to deploy, upload and remove images from S3.
Use CloudWatch to see the final score change based on criteria added.
Compare Faces
In Fotostatur/ImageAnalyzer/Functions.cs
edit the CompareFaces
and ScoreCompare
methods.
- Add a "headshot" of someone to the
Fotostatur/headshots
directory. - In
Fotostatur/Module.yml
, findHeadshotFileName
and replace theTODO
with the filename (include extension) of the headshot.Note: These variables can be accessed from:
_headshotFileName
,_comparingImageBucket
, and_comparingImageKey
. SeeInitializeAsync
inFotostatur/ImageAnalyzer/Functions.cs
. - Compare the headshot and the image uploaded.
- Score the results from comparison using the
AddTotals
helper function to keep a running total.
Deploy with dotnet lash deploy Fotostatur --tier Sandbox
Test your code by using the CLI commands above to deploy, upload and remove images from S3.
Use CloudWatch to see the final score change based on criteria added.
Detect Faces
In Fotostatur/ImageAnalyzer/Functions.cs
edit the DetectFaces
and ScoreFaces
methods.
DetectFacesAsync Method DetectFacesAPI
- Detect faces from the image uploaded.
- See
ScoreFaces
for a commented list of objects to generate criteria with. Use at least one. - Score the results from generated criteria using the
AddTotals
helper function to keep a running total.
Deploy with dotnet lash deploy Fotostatur --tier Sandbox
Test your code by using the CLI commands above to deploy, upload and remove images from S3.
Use CloudWatch to see the final score change based on criteria added.
Upload Image to Twitter Profile
To obtain Twitter keys, use the steps provided at the presentation. To create tokens you must have a Twitter account and create an app on the Twitter Developer Site.
-
Encrypt the Twitter keys
TwitterConsumerKey
,TwitterConsumerSecret
,TwitterAccessToken
,TwitterAccessSecret
.lash encrypt SECRET
-
In
Fotostatur/Module.yml
, uncomment theTwitterConsumerKey
,TwitterConsumerSecret
,TwitterAccessToken
,TwitterAccessSecret
and add each encrypted value to their respective location.
In Fotostatur/ImageAnalyzer/Functions.cs
do the following
-
In method
InitializeAsync
, uncomment_consumerKey
,_consumerSecret
,_accessToken
,_accessTokenSecret
-
In method
ProcessMessageAsync
, uncommentawait DownloadS3Image();
-
In method
DownloadS3Image
, save the image locally from S3 -
In method
ProcessMessageAsync
, uncommentResizeImage();
-
In method
ResizeImage
, process the image -
In method
ProcessMessageAsync
, uncommentTwitterUpload();
-
In method
TwitterUpload
, change theLOCAL FILE PATH
-
In method
ProcessMessageAsync
, edit the_criteriaThreshold
from50
to desired number. -
(Optional) In method
ProcessMessageAsync
, uncommentUploadImage();
-
(Optional) In method
UploadImage
, make backup in s3 of the image posted
Deploy with dotnet lash deploy Fotostatur --tier Sandbox
Test your code by using the CLI commands above to deploy, upload and remove images from S3.
Use CloudWatch to see the final score change based on criteria added.
Check Twitter for the new profile picture.
Remove Fotostatur and Lambdasharp installation
- Empty the S3 bucket for
Fotostatur
(the one uploading images to). - On the CloudFormation page in the AWS console, select the stack named
{tier}-Fotostatur
, clickActions
and thenDelete Stack
.
- On the S3 bucket page in the AWS console, empty the bucket that begins with
{tier}-lambdasharp-s3package
. - Delete the stack
{tier}-LambdaSharp
- On the S3 bucket page in the AWS console, empty the bucket that begins with
lambdasharptool-default-deploymentbucket
. - Remove the cli profile stack named
LambdaSharpTool-{cli-profile}
.