Over a million developers have joined DZone.

Face Detection Has Never Been This Simple

DZone's Guide to

Face Detection Has Never Been This Simple

Rekognition is the result of decades-long research and deep learning on billions of images. Let's see how we can put it to use!

· AI Zone ·
Free Resource

EdgeVerve’s Business Applications built on AI platform Infosys Nia™ enables your enterprise to manage specific business areas and make the move from a deterministic to cognitive approach.

According to the Amazon Rekognition website:

Amazon Rekognition is an AWS service that makes it really easy for you to enable image analysis in your applications. With Rekognition, you can detect and label objects, scenes, or faces, recognize celebrities, and identify inappropriate content in images. You can also search and compare faces, which is helpful for use cases such as employee verification and marking attendance. Rekognition's API enables you to quickly add sophisticated deep learning-based visual search and image classification to your applications.

Rekognition is the result of decades-long research and doing deep learning on billions of images. Let's see how we can put it to use!

What Does It Have in Store for Us?

Let's see how easy it is to implement the API, how reliable it is, and whether it's scalable.

1. How Easy Is It to Implement the API?

I made use of the AWS SDK, which made this super simple. Let me give you an example of the code that would provide image recognition for you:

DetectLabelsRequest request = new DetectLabelsRequest()
        .withImage(new Image()

try {

    DetectLabelsResult result = rekognitionClient.detectLabels(request);
    List  labels = result.getLabels();

    System.out.println("Detected labels for " + photo);
    for (Label label: labels) {
        System.out.println(label.getName() + ": " + label.getConfidence().toString());

} catch (AmazonRekognitionException e) {

2. How Reliable Is It?

I've tested it with DetectLabels and SearchFacesByImage (face recognition) and can only talk from my experience, but it is pretty damn reliable! You can change the ConfidenceThreshold to allow flexibility around this, but I found that 90% was a good match for taking various images in diverse environments.

3. Is It Scalable?

Absolutely. With Amazon Rekognition, you only pay for the number of images you analyze and the face metadata you store. I'm using the free tier as of now. (As with all AWS services, you pay for Rekognition on the tiered pricing model.)

What Can It Do?

Common use cases for using Amazon Rekognition include the following:

  • Searchable image library: Amazon Rekognition makes images searchable so that you can discover objects and scenes that appear in them.
  • Face-based user verification: Amazon Rekognition enables your applications to confirm user identities by comparing a live image with a reference image.
  • Sentiment and demographic analysis: Amazon Rekognition detects emotions such as happiness, sadness, or surprise, as well as demographic information such as gender from facial images.
  • Facial recognition: With Amazon Rekognition, you can search your image collection for similar faces by storing faces with the IndexFaces API operation. You can then use the SearchFaces operation to return high-confidence matches. A face collection is an index of faces that you own and manage. Identifying people based on their faces requires two major steps in Amazon Rekognition:
    1. Index the faces.
    2. Search the faces.
  • Image moderation: Amazon Rekognition can detect explicit and suggestive adult content in images. Developers can use the returned metadata to filter inappropriate content based on their business needs. These labels indicate specific categories of adult content, allowing granular filtering and management of large volumes of user-generated content (UGC). 
  • Celebrity recognition: Amazon Rekognition can recognize celebrities within supplied images. Rekognition can recognize thousands of celebrities across a number of categories, such as politics, sports, business, entertainment, and media.

How Does It Work?

The Computer Vision API operations that Amazon Rekognition provides can be grouped into the following categories:

  • Non-storage API operations: The API operations in this group do not persist any information on the server. You provide input images; the API performs the analysis and returns results; but nothing is saved on the server. The API can be used for operations such as the following:
    • Detect labels or faces in an image. A label refers to objects (flower, tree, table), events (wedding, graduation, birthday party), or concepts (landscape, evening, nature). The input image you provide to these API operations can be in JPEG or PNG format.
    • Compare faces in two images and return faces in the target image that match a face in the source image.
    • Detect celebrities in images.
    • Analyze images for explicit or suggestive adult content.
  • Storage-based API operations: Amazon Rekognition provides an API operation that detects faces in the input image and persists facial feature vectors in a database on the server. Amazon Rekognition provides additional API operations you can use to search the persisted face vectors for face matches. None of the input image bytes are stored.

Rekognition in Action

The question arises: How do we quickly set it up and get it working? AWS Rekognition provides free usage of up to 5,000 API calls and up to 1,000 images to be indexed (both limits on a per month basis). You would just need to signup for AWS and avail these under free tier usage.

You can find one of my projects on Rekognition here.

It's pretty cool!

I will be adding a detailed post on setting up Rekognition soon. For now, we're going to see it in action. Check out the below video:

Adopting a digital strategy is just the beginning. For enterprise-wide digital transformation to truly take effect, you need an infrastructure that’s #BuiltOnAI. Click here to learn more.

ai ,face detection ,image recognition ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}