Voiced by Amazon Polly |
Introduction
Amazon Rekognition is a cloud-based AI service provided by AWS which utilizes deep learning technology to analyze the images and videos stored in Amazon S3. It can analyze images and videos for detecting objects, detecting faces, comparing the faces on an image or video, detecting unsafe objects in an image or video, search faces by image and sentiment analysis.
Pioneers in Cloud Consulting & Migration Services
- Reduced infrastructural costs
- Accelerated application deployment
Detect Faces API in Amazon Rekognition
Detect Faces API is used to recognize the faces on images and videos, which helps to compare the faces and determine the number of images containing duplicate faces in an image. It is also useful for user verification by registering the faces in a collection and uses facial authentication.
This API provides the response where we will get the number of faces and their attributes like gender, age, beard, smile, sunglasses, eyeglasses, eyes open, mouth open, emotions, and hair. Also, face detection API provides information about pose, quality, and eye direction. Finally, confidence is about all the attributes of a face based on the percentage detected in an image.
This system helps predict whether a face exists in an image or not. The main critical component of face detection is Confidence scores which give the final result by comparing the percentages of all the attributes of a face, and users should consider this component confidence score which helps to make decisions based on the system’s output.
Detecting the Faces on an Image stored in Amazon S3
Now, we will analyze the image below using Detect Faces API on an image in Amazon S3 and find below the sample code of Python and its response.
The below sample code is for performing the Detecting Faces API on an image stored in an Amazon S3 bucket:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import boto3 import json def detect_faces(photo, bucket, rek_client): response=rek_client.detect_faces(Image={'S3Object':{'Bucket':bucket,'Name':photo}}, Attributes=['ALL']) with open('./sample-detectFaces.json', 'w') as file: json.dump(response, file,indent=4) file.close() print('Detected faces for ' + photo) return len(response['FaceDetails']) def main(): photo='face_detector.png' bucket='samplestorage' rek_client = boto3.client("rekognition",region_name='ap-south-1') face_count=detect_faces(photo, bucket, rek_client) print("Faces detected: " + str(face_count)) main() |
Sample Response of Detect Faces API on Images and Its Attributes
By default, we will be getting all the attributes of a face present in an image because we have mentioned ALL of the Attributes in the above code. The face detection API response will have all the below keys in each face object with two keys: value and confidence, with their Boolean values and percentage of confidence. Below are the parameters which we are getting in this scenario.
Detecting the Faces on a Video stored in Amazon S3
It’s also possible to use Detect Faces API on video, but before calling the API on a video, we need to pass the JobID, which will get generated from the start_face_detection API. The code below is for calling the detect faces API on a video.
Get_face_detection API will provide the array of faces, which contains information about the number of faces detected in the video and attributes which comes in response mentioned below.
This API provides the information about
- The location of the faces detected in the video frame at a time.
- Number of faces detected in the video.
- The position of the eyes was detected in the video.
The below sample code is for performing the Detecting Faces API on a video stored in an Amazon S3 bucket:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import boto3 from boto3.exceptions import Boto3Error import json import time def StartFaceDetection(rek_client,bucket,video): response=rek_client.start_face_detection(Video={'S3Object': {'Bucket': bucket, 'Name': video}},FaceAttributes='ALL') startJobId=response['JobId'] return startJobId def GetFaceDetectionResults(rek_client,jobId): maxResults = 100 finished = False while finished == False: response = rek_client.get_face_detection(JobId=jobId, MaxResults=maxResults) status=response['JobStatus'] if status in ['SUCCEEDED','FAILED']: with open('./SME-Linux-Video/Data-detectFaces.json', 'w') as file: json.dump(response, file,indent=4) file.close() break time.sleep(5) def detect_faces(): bucket = 'samplestorage' video = 'sample-interview.mp4' rek_client = boto3.client("rekognition",region_name='ap-south-1') jobId=StartFaceDetection(rek_client,bucket,video) print(GetFaceDetectionResults(rek_client,jobId)) detect_faces() |
The above code provides the response having all attributes we have in the above Detect Faces API response on Image except these two FaceOccluded and EyeDirection attributes.
Use cases of Amazon Rekognition Service
- Facial Detection and Analysis
- Moderating the inappropriate content in both images and videos
- Detecting the objects
- Comparing the faces present in images and videos
Conclusion
Amazon Rekognition is a powerful AI service that uses deep learning algorithms, offering various use cases for image and video analysis.
Drop a query if you have any questions regarding Amazon Rekognition and we will get back to you quickly.
Making IT Networks Enterprise-ready – Cloud Management Services
- Accelerated cloud migration
- End-to-end view of the cloud environment
About CloudThat
CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.
CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, AWS GenAI Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, Amazon ECS Service Delivery Partner, AWS Glue Service Delivery Partner, Amazon Redshift Service Delivery Partner, AWS Control Tower Service Delivery Partner, AWS WAF Service Delivery Partner, Amazon CloudFront Service Delivery Partner, Amazon OpenSearch Service Delivery Partner, AWS DMS Service Delivery Partner, AWS Systems Manager Service Delivery Partner, Amazon RDS Service Delivery Partner, AWS CloudFormation Service Delivery Partner, AWS Config, Amazon EMR and many more.
FAQs
1. Is Amazon Rekognition service suitable for real-time analysis?
ANS: – Yes, it’s suitable for performing this service on real-time analysis for applications requiring immediate video insight.
2. What about the pricing of this service?
ANS: – It follows a pay-as-you-go pricing model, and it depends on the number of API calls on images and videos.

WRITTEN BY Sridhar Andavarapu
Sridhar Andavarapu is a Senior Research Associate at CloudThat, specializing in AWS, Python, SQL, data analytics, and Generative AI. With extensive experience in building scalable data pipelines, interactive dashboards, and AI-driven analytics solutions, he helps businesses transform complex datasets into actionable insights. Passionate about emerging technologies, Sridhar actively researches and shares insights on AI, cloud analytics, and business intelligence. Through his work, he aims to bridge the gap between data and strategy, helping enterprises unlock the full potential of their analytics infrastructure.
Comments