This is a simple demo of Amazon Rekognition service. It uses Next.js to create a simple application that calls Amazon Rekognition Moderating content tool to moderate image content and get the labels of the moderated images.
Amazon Rekognition is a cloud-based image and video analysis service that makes it easy to add advanced computer vision capabilities to your applications. The service is powered by proven deep learning technology and it requires no machine learning expertise to use.
Amazon Rekognition includes a simple, easy-to-use API that can quickly analyze any image or video file that’s stored in Amazon S3.
Developers can add features in their applications that detect objects, text, and unsafe content, analyze images/videos, and compare faces to your application using Rekognition's APIs.
For this project, the focus is on image analysis, and our first feature is to detect inappropriate content in an image, but there are many other features that can be used to analyze images:
- Object, Scene, and Concept Detection - Detects and classify objects, scenes, concepts, and celebrities in images.
- Text Detection - Detect and recognize printed and handwritten text in images in a variety of languages.
- Unsafe Content - Detect and filter explicit, inappropriate, and violent content and images. Detects granular unsafe content labels.
- Celebrity recognition - Recognize tens of thousands of celebrities in your images across different categories, such as politicians, athletes, actors, and musicians.
- Facial Analysis - Detect, analyze, and compare faces, along with facial attributes, such as gender, age, and emotions. Use cases may include user verification, cataloging, people counting, and public safety.
- Custom Labels - Build custom classifiers to detect objects specific to your use case, such as logos, products, characters.
- Image Properties - Analyze image properties like quality, color, sharpness, contrast.
As per the Amazon Rekognition documentation, you can use the DetectModerationLabels operation to determine if an image contains inappropriate or offensive content.
- The image must be in either a .jpg or a .png format
- You can provide the input image as an image byte array or specify an Amazon S3 object
- You need to have the AWS CLI or the appropriate AWS SDK installed
- You need to create or update an user with
AmazonRekognitionFullAccessandAmazonS3ReadOnlyAccesspermissions.
The input to DetectModerationLabel is an image. It can retrieve input images from an S3 bucket, or you can provide them as image bytes (base64-encoded image bytes).
S3 buckets
const params = {
Image: {
S3Object: {
Bucket: input.s3BucketName,
Name: input.filePath,
},
},
MinConfidence: 70,
};Image bytes
const params = {
Image: {
Bytes: imageBytes,
},
MinConfidence: 50,
};MinConfidence is the minimum confidence that Amazon Rekognition Image must have in the accuracy of the detected label for it to be returned in the response.
If you don't specify MinConfidence, the operation returns labels with confidence values greater than or equal to 50%.
Image
Response:
moderationLabels: [
{
Confidence: 99.96949768066406,
Name: 'Weapons',
ParentName: 'Violence',
TaxonomyLevel: 2
},
{
Confidence: 99.96949768066406,
Name: 'Violence',
ParentName: '',
TaxonomyLevel: 1
}
]First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.
