Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Facial Recognition of Celebrities With Amazon Rekognition

DZone's Guide to

Facial Recognition of Celebrities With Amazon Rekognition

Learn how to use Java SDK and Amazon Rekognition to develop a simple and useful application that recognizes celebrity's faces.

· AI Zone
Free Resource

Find out how AI-Fueled APIs from Neura can make interesting products more exciting and engaging. 

As stated on the Amazon Web Services website, Amazon Rekognition is a service that enables you to add image analysis to your applications. With Rekognition, you can detect objects, scenes, and faces in images. Among the most important features offered by Amazon Rekognition are:

  • Objects and scene detection
  • Moderation of images
  • Facial analysis
  • Facial recognition
  • Celebrity recognition

In this technical example, we're going to use Java SDK to show how to develop a simple and useful application that recognizes celebrity's faces in order to demonstrate the capabilities of the service.

Image title

We picked various pictures of recognized celebrities like Cristiano Ronaldo, Celine Dion, and Sting, obtaining favorable results, as shown in the infographic.

For the technical side, we will focus on the most important steps and will omit the less-specific parts (you can get all the code at GitHub).

Steps

Create an Amazon Rekognition client using AmazonRekognitionClientBuilder, including the Region to be used and a RecognizeCelebritiesRequest containing the representation in bytes of the picture:

Image title

AmazonRekognition amazonRekognition = AmazonRekognitionClientBuilder
  .standard().withRegion(Regions.US_WEST_2).build();   

RecognizeCelebritiesRequest request = new RecognizeCelebritiesRequest()    .withImage(new Image().withBytes(imageBytes));

Create a RecognizeCelebritiesResult object that will contain the obtained results:

Image title

RecognizeCelebritiesResult result = amazonRekognition.recognizeCelebrities(request);

Display the recognized celebrity information:

Image title

List celebs=result.getCelebrityFaces();    
System.out.println(celebs.size() + ” celebrity(s) were recognized.\n”);    
List metadata = new ArrayList();      

for (Celebrity celebrity: celebs) {  
// Name        
System.out.println(“Celebrity recognized: ” + celebrity.getName());   metadata.add(“Celebrity recognized: ” + celebrity.getName());   
// Id        
System.out.println(“Celebrity ID: ” + celebrity.getId());        
metadata.add(“Celebrity ID: ” + celebrity.getId());               
// Extra info        
System.out.println(“Further information (if available):”);       
metadata.add(“Further information (if available):”); 

for (String url: celebrity.getUrls()){           
System.out.println(url);          
metadata.add(url);        
}        

Currently, Amazon Rekognition only supports JPG and PNG formats, which is a disadvantage compared to Google Cloud Vision, which provides support for a wide range of formats such as GIF, BMP, and RAW, among others. However, it should be noted that during the tests performed, there were no performance issues due to the type of format, but the tool was more effective when the faces were clearly visible or at a frontal angle, and when the contrast with the background is high.

Another feature to note is that the API was designed to include as many celebrities as possible based on feedback from AWS clients, so new names are constantly being added to the list after analysis. Taking this into consideration, we did some extra testing using celebrity images from countries like Panama and Colombia to diversify the evidence based on a wider cultural spectrum. The results we obtained were as follows:

Image title

In the first two tests satisfactory results were observed. The tool was able to recognize Panamanian boxing legend Roberto Durán and the well-known Colombian footballer of Bayern Münich, James Rodriguez. We did a third test using a lower-resolution image to test the limits of the tool and did not get favorable results when trying to recognize the great martial artist of all time, Bruce Lee.

Image title

Taking these results into account, it can be affirmed that the quality and resolution of the image are an aspect to consider when using the tool. If it is desired to obtain favorable results, it is important to ensure the use of images of considerable quality, taking into account that the service still seems to be developing improvements as the deep learning models are fed.

Image title

Although Amazon Rekognition is relatively new to the market, we were impressed by its capabilities, competitive pricing, and features. There's a great potential for Rekognition to become a standard for image analysis based on deep learning algorithms, along with competing services like Clarifai and Google's Vision API.

The near future looks very promising for software development focused on artificialintelligence, a market that will definitely open new horizons for the creation of impressive tools that could have a beneficial impact on our society.

To find out how AI-Fueled APIs can increase engagement and retention, download Six Ways to Boost Engagement for Your IoT Device or App with AI today.

Topics:
ai ,amazon ,machine learning ,amazon rekognition ,image recognition ,visual analytics ,tutorial ,facial recognition ,java sdk

Published at DZone with permission of Dario Carrasquel, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}