Detecting Faces From Videos Using Rekognition

Detecting Faces from Videos using Rekognition in Serverless Architecture

You’re walking through an airport, and without a hitch, security systems recognize and verify your identity, ensuring a seamless experience from check-in to boarding. 

Or imagine a retail store that not only identifies loyal customers as they enter but also tailors special offers based on their past purchases and preferences. 

These scenarios aren’t scenes from a sci-fi movie—they’re real-world applications of face detection technology powered by Amazon Rekognition and serverless architecture.

In this blog post, we’ll explore how you can leverage these cutting-edge technologies to detect faces from videos, making your systems smarter, faster, and more efficient.

Whether you’re aiming to boost security, enhance customer experiences, or unlock new possibilities in your industry, understanding and implementing this technology can give you a significant edge. 

So, let’s dive in and see how detecting faces from videos using rekognition in a serverless setup can transform your tech landscape.

Rekognition is a powerful image and video analysis service provided by AWS. 

It can identify objects, people, text, scenes, and activities in images and videos, as well as detect any inappropriate content. 

For face detection, Rekognition can locate faces within images and videos, analyze facial attributes (like age range, emotions, and gender), and even recognize individuals if you have a pre-existing collection of face data.

With the rise of Artificial Intelligence and Cognitive Services, it’s now pretty easy to achieve things we used to hear as fairy tales or as science fiction in childhood. In a just matter of 10 years, we have seen servers shifting their places from delicate server rooms to clouds and now things are getting popular around serverless architecture. The software engineers of my company Craftsmen always work with bleeding-edge technologies like this. In this article, I am going to share an interesting topic based on the following architecture.

Detecting Faces From Videos Using Rekognition

We have few videos stored in S3 bucket. Also we have few images of people stored in another S3 bucket. Using some ‘magic’ we would like to know which people are being shown in which video and at what time.

Here is the magic we shall use the AWS Rekognition service. Relevant code snippets are written in Node.js. I shall not show how to configure API Gateway with Lambda here as it can be easily done and if you find any difficulties please google it and you will find ample help from there :). Suppose we have a bunch of images of different people uploaded in an S3 bucket. The Rekognition engine does the facial analysis and faces recognition based on a collection of its own. We need to register these images for this collection.

const rekognition = new AWS.Rekognition({ region: 'eu-west-1' });
const params = {
    CollectionId: 'rekognitionFaceCollectionId', // Id of Face Collection 
    Image: {
        S3Object: {
            Bucket: 'IAmABucketContainingImagesOfPerson',
            Name: 'Alex.jpg',
        },
    },
};
const result = await rekognition.indexFaces(params).promise();

The face collection can be created using the following AWS CLI command. Needless to say that this collection can be created programmatically but in order to keep this article I am ignoring this here.

aws rekognition create-collection --collection-id 
'rekognitionFaceCollectionId' --region eu-west-1

Let’s assume that we have one CognitiveEngineApi exposed which takes a video item reference as an input. The Rekognition engine is an independent system and it communicates back with its processing status through SNS. This can be seen in the architecture diagram above. The following code snippet will trigger a face detection command in the CognitiveEngineApi.

const params = {
    Video: {
        S3Object: {
            Bucket: 'BucketOfStoredVideos',
            Name: 'RandomVideoWithPeoples.mp4',
        },
    },
    CollectionId: 'rekognitionFaceCollectionId',
    NotificationChannel: {
        RoleArn: 'ArnOfRekognitionRoleFromIAM',
        SNSTopicArn: 'ArnOfSNS',
    },
};
const rekognitionJob = await rekognition.startFaceSearch(params)  .promise();

Upon completion of the analysis process, the Rekognition Engine will notify through SNS. So we need to have one more lambda which will be integrated with this SNS. Here we call this lambda as CognitiveServiceTrigger as can be seen in the architectural diagram above. If the analysis is completed successfully then in the SNS topic it sends the RekognitionJobId through which we can query the result from the Rekongnition Engine.

const params = {
    JobId: 'rekognitionJobIdFromSns',
};
const faceDetectionResult = await rekognition.getFaceSearch(params).promise();

Benefits of Using Rekognition and Serverless Architecture

  1. Scalability: Automatically scales to handle varying loads, ensuring that your application remains responsive even during peak times.
  2. Cost-Efficiency: You only pay for what you use. There are no upfront costs or infrastructure to maintain, which significantly reduces operational expenses.
  3. Simplified Management: No need to manage servers or infrastructure. AWS handles the heavy lifting, allowing you to focus on developing and deploying your application.
  4. Speed: Fast and efficient processing of video files, enabling real-time or near-real-time face detection.
  5. Flexibility: Easily integrates with other AWS services, allowing you to build comprehensive solutions tailored to your specific needs.

Real-World Applications

Amazon Rekognition and serverless architecture have been adopted by numerous companies across various industries. Here are some notable examples:

1. Security and Surveillance

Company: Ring

Application: Ring uses Amazon Rekognition to enhance its security cameras and doorbells. The face detection capabilities enable Ring devices to recognize familiar faces and notify homeowners of known visitors or potential intruders.

Benefits: Enhanced security and peace of mind for homeowners, as well as improved response times in case of suspicious activity.

2. Retail and Marketing

Company: Coca-Cola

Application: Coca-Cola uses Rekognition to analyze customer demographics and emotions in retail environments. By understanding how customers interact with their products, Coca-Cola can tailor marketing strategies and improve customer experiences.

Benefits: Better-targeted marketing campaigns, increased customer satisfaction, and higher sales conversion rates.

3. Entertainment

Company: Netflix

Application: Netflix leverages Rekognition to create interactive and personalized viewing experiences. By recognizing faces in user-uploaded content, Netflix can suggest relevant movies and shows that feature the user’s favorite actors.

Benefits: Enhanced user engagement, personalized content recommendations, and increased viewer retention.

Global Impact

The integration of face detection technology with serverless architecture has a profound global impact. Here are some ways this combination is making a difference:

1. Improved Security

Globally, organizations and governments are using face detection technology to enhance security measures. From airports to public spaces, the ability to detect and recognize faces in real-time helps prevent crime, identify suspects, and ensure public safety.

2. Healthcare Advancements

In the healthcare sector, face detection technology is being used to monitor patients, detect signs of distress, and even diagnose certain medical conditions. For example, facial analysis can help identify early symptoms of diseases like Parkinson’s or monitor emotional well-being in mental health patients.

3. Disaster Response

During natural disasters, face detection technology can be crucial for identifying and locating missing persons. By analyzing footage from drones or security cameras, rescue teams can quickly identify individuals and coordinate rescue efforts more effectively.

4. Enhanced Accessibility

Face detection technology is also improving accessibility for people with disabilities. For instance, it can be used to create more intuitive and accessible interfaces for visually impaired users, enabling them to interact with devices and services more easily.

Challenges and Considerations

While the benefits of using Amazon Rekognition and serverless architecture are significant, it’s essential to consider some potential challenges and ethical considerations:

1. Privacy Concerns

The use of face detection technology raises privacy concerns. Organizations must ensure that they comply with data protection regulations and implement robust measures to protect users’ personal information.

2. Bias and Fairness

Face detection algorithms can sometimes exhibit bias, leading to unfair treatment or inaccurate results for certain demographic groups. Continuous monitoring and improvement of these algorithms are necessary to ensure fairness and accuracy.

3. Data Security

Storing and processing sensitive data, such as facial images, requires stringent security measures. Organizations must implement best practices for data encryption, access control, and secure storage to prevent data breaches.

Conclusion

By following the steps outlined above, you can set up a scalable and cost-effective face detection system in no time. Whether you’re enhancing security, improving marketing strategies, or creating engaging user experiences, this technology opens up a world of possibilities.

facedetectionResult is a JSON object which contains JobStatus and a map of detection person with relevant data. Details of which can be found at this link.

Now depending on your business need you can extract and process data from the returned result which can be stored in DynamoDB ( or even in S3).

So far I have discussed a pretty simple use case with the Rekognition engine but it’s possible to do incredible things with this engine like sentiment analysis, finding and reading text in images, and on video that is hard to see with the naked eyes, etc which we are doing at Craftsmen!

If you are still reading this line then I hope, at least you got an idea about a standard serverless architecture with AWS Rekognition engine to do different ‘cognitive’ magic.

Thanks for your time!

Hire Exceptional Developers Quickly

Share this blog on

Hire Your Software Development Team

Let us help you pull out your hassle recruiting potential software engineers and get the ultimate result exceeding your needs.

Contact Us Directly

Address:

Plot # 272, Lane # 3 (Eastern Road) DOHS Baridhara, Dhaka 1206

Talk to Us
Scroll to Top