amazon-web-servicesandroid-studioface-recognitionamazon-rekognitionaws-amplify-sdk-android

AWS facial rekognition within an Android app


I'am trying to make an Android application which can send images taken by a camera on an Android tablet to AWS Rekognition. It's the intention that pictures will be directly send to the AWS Rekognition service without the need of an S3 bucket. The picture itself don't need to be saved in the cloud. Only the face metadata need to be stored on AWS in a collection. Afterwards the ultimate goal is for a person to be able to capture his face again, and AWS says there is a match with a previous face in the collection.

There is a lot of information on the internet. But most of the times AWS suggest the Amplify framework. And I don't really know if this is necessary in such simple case.

I have already done all the steps in the AWS CLI (and these work) but I don't succeed to do these steps into Android studio. Below I describe the steps that I have done in the AWS CLI. I would do these steps in Android Studio, but I'm not a pro in programming this language. (I have already made a collection within the AWS CLI.)

First I index a face which can be found by AWS into a picture. In my AWS CLI code I use S3 as an example. It should be the intention that I can send the picture directly to AWS Rekognition. This action only need to be done if someone specially push a button. So taking a picture and sending it to AWS Rekognition to index the face in a specific collection.

aws rekognition index-faces --image '{"S3Object":{"Bucket":"bucketName","Name":"picture1.jpg"}}' --collection-id "collectionName" --max-faces 1 --quality-filter "AUTO" --detection-attributes "DEFAULT" --external-image-id "picture1.jpg"

Then when a user push another button it need to take a picture again and it need to be send to AWS Rekognition to search the collection by the image which was sent. I have already succeeded this with the following AWS CLI code. It should also be the intention to send the picture directly to AWS without the need of S3. AWS returns a match with a face which is already in the collection.

aws rekognition search-faces-by-image --image '{"S3Object":{"Bucket":"bucketName","Name":"picture.jpg"}}' --collection-id "collectionName"

Again I'am not a professional in Android studio, so it would be very nice if someone haves a quite easy solution. It would also be very nice if someone can tell me if the Amplify framework is really necessary. Thanks in advance!


Solution

  • You don't have to use Amplify, you can use Rekognition through the AWS Java SDK.

    To achieve this same functionality you're getting with the CLI, you can first index the face(s) in the collection using IndexFacesRequest, or you can forego this and create the collection manually over the CLI if this is a one-time operation.

    To search the collection's faces by image, you would simply need to modify the following code snippet to pass in a byte-64 encoded image instead of the S3 URL. Full documentation for the searchFacesByImage() method here.

    AmazonRekognition client = AmazonRekognitionClientBuilder.standard().build();
    SearchFacesByImageRequest request = new SearchFacesByImageRequest().withCollectionId("myphotos")
            .withImage(new Image().withS3Object(new S3Object().withBucket("mybucket").withName("myphoto"))).withMaxFaces(5).withFaceMatchThreshold(95f);
    SearchFacesByImageResult response = client.searchFacesByImage(request);