DEV Community

Cover image for Face recognition of celebrities in Java with Amazon Rekognition
Darío Carrasquel
Darío Carrasquel

Posted on

Face recognition of celebrities in Java with Amazon Rekognition

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 celebrities' faces in order to demonstrate the capabilities of the service.

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). In this example, we will use the Java SDK.

Steps

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

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

RecognizeCelebritiesRequest request = new RecognizeCelebritiesRequest()
    .withImage(new Image().withBytes(imageBytes));
Enter fullscreen mode Exit fullscreen mode

 
2) Create a RecognizeCelebritiesResult object that will contain the obtained results:

RecognizeCelebritiesResult result = amazonRekognition.recognizeCelebrities(request);
Enter fullscreen mode Exit fullscreen mode

 

3) Display the recognized celebrity information:

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);        
  }
}
Enter fullscreen mode Exit fullscreen mode

 

Currently, Amazon Rekognition only supports JPG and PNG formats, which is a disadvantage compared to Google Cloud Vision that 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, and better effectiveness of the tool could be observed when the faces were clearly visible or at a frontal angle when the contrast with the background was notorious.
 
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 some 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:
 

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, 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.
 

 
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.
 
Amazon Rekognition it's been in the market since 2016, offering great capabilities like scalability, high availability, and competitive pricing. 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, Microsoft Cognitive Services, and Google’s Vision API.
 

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

Top comments (0)