DEV Community

Cover image for Amazon Rekognition: Add AI Vision to Your Applications
Tanseer for AWS Community Builders

Posted on

Amazon Rekognition: Add AI Vision to Your Applications

Give your app the ability to understand images and video, with no machine learning knowledge required. Stop three in the AWS Hidden Gems series.

About this series

Most AWS learning stops after EC2, S3, IAM, and Lambda. But AWS has over two hundred services, and many of the most useful ones rarely appear in tutorials.

AWS Hidden Gems covers those underrated services you shouldn't ignore. Each article picks one, then explains why it exists, what it does, where it fits, and how to set it up from the console. Know the four basics above and you can follow along. Everything else gets explained as it comes up.

Today's service: Amazon Rekognition

Your app can store and show images. Rekognition lets it understand them too: what objects are in a photo, what text appears, whether a face matches, or whether an image is unsafe. You call an API and get the answer back, with no models to train.

Why does this service exist?

Teaching a computer to understand images is one of the hardest problems in software. Traditionally it meant hiring machine learning engineers, collecting and labeling thousands of training images, renting GPUs, which are specialized chips for training models, and maintaining that model over time. That is out of reach for most teams.

Rekognition removes all of that. AWS trained the deep learning models already, on huge datasets, and exposes them through a simple API. You send an image, you get structured results back. The hard research and training is done, and you just make a call.

What is Amazon Rekognition?

Rekognition is a managed computer vision service. Computer vision means software that interprets images and video the way a person visually would.

It can:

  • Detect objects and scenes, returning labels like dog, car, or beach with a confidence score
  • Detect and analyze faces, including expressions and an estimated age range
  • Compare two faces, or search a face against a stored collection to find a match
  • Read text that appears inside an image, like a sign or a label
  • Flag unsafe or explicit content for moderation
  • Detect safety equipment such as helmets and masks in workplace photos
  • Analyze stored or live video for the same things across frames For images, results come back instantly. For video, Rekognition processes the file in the background and notifies you when it is done. If the built in labels are not enough, Custom Labels lets you train it to recognize your own specific objects from a small set of example images.

A real world problem

A marketplace app lets users upload photos of items they want to sell. Some upload blurry pictures, some pick the wrong category, and a few upload content that breaks the rules.

Reviewing every photo by hand does not scale past a few hundred a day. The team needs each upload checked automatically: is there actually a product in the photo, does it match the chosen category, and is the content safe to show.

Rekognition handles all three. One call returns labels to confirm the category, and another checks for unsafe content, so only clean, correctly tagged listings go live. No human in the loop for the routine cases.

Real world use cases

  • Marketplaces and social apps moderate uploaded images automatically for unsafe content
  • Retail tags product photos with labels so search and filtering work without manual data entry
  • Media companies find every clip a specific person or object appears in across a video library
  • Security and access systems match a face at a door against a collection of approved people
  • Manufacturing checks photos for required safety gear before allowing entry to a site
  • Apps make images searchable by reading the text printed inside them The pattern is turning raw pixels into structured data your app can act on.

Where it fits in AWS

Images and video usually live in S3. A common setup: a user uploads an image to S3, that upload triggers a Lambda function, the function calls Rekognition, and the results get stored in DynamoDB for your app to use. For faces, Rekognition keeps a collection, which is a searchable index of face data. For video, results are delivered through SNS, the AWS notification service, when the background job finishes.

flowchart LR
    A[User uploads image] --> B[S3 bucket]
    B -->|Upload event| C[Lambda function]
    C -->|Analyze image| D[Rekognition]
    D -->|Labels and results| C
    C -->|Store results| E[DynamoDB]
Enter fullscreen mode Exit fullscreen mode

Rekognition is the vision brain you call from your own code. Everything around it, meaning storage, triggers, and results, uses services you already know.

How the workflow runs

For an image, the flow is one step: send the image to Rekognition, either its S3 location or the raw bytes, and it returns labels, faces, text, or moderation results as JSON. For video, it is three steps: start a job on a video in S3, Rekognition processes it in the background, and it sends a notification through SNS when the results are ready to fetch.

Face search adds a setup step. First you add known faces to a collection with IndexFaces. Then, to identify someone, you search a new face against that collection and get back the closest matches.

flowchart TD
    A[Image or video] --> B{Type?}
    B -->|Image| C[Call Rekognition, get results instantly]
    B -->|Video| D[Start a job]
    D --> E[Rekognition processes in background]
    E --> F[SNS notifies you]
    F --> G[Fetch results]
Enter fullscreen mode Exit fullscreen mode

Setting it up in the AWS Console

The Rekognition console has built in demos, so you can try it on your own image before writing any code.

  1. Sign in to the AWS Console, search for Rekognition, and open it. Check the region in the top right corner.
  2. In the left menu under Demos, click Label detection. This is the feature that identifies objects and scenes.
  3. Upload an image from your computer, or use one of the samples provided. Rekognition analyzes it right away.
  4. Look at the results. On the right you see a list of labels, each with a confidence score from 0 to 100. The image on the left highlights where objects were found. Try a few different images to see how the labels change.
  5. Explore the other demos in the left menu, such as Facial analysis, Text in image, and Content moderation, to see the range of what Rekognition returns.
  6. To use Rekognition from your own code, create an IAM user or role with the AmazonRekognitionReadOnlyAccess policy for the detection APIs, plus s3:GetObject permission on the bucket holding your images. This lets your code call Rekognition and read the images it needs to analyze.
  7. To confirm your setup works outside the console, run the code in the next section against an image in your S3 bucket and check that labels come back. Common mistakes: an access error usually means the IAM role is missing either Rekognition permission or read access to the S3 bucket, so check both. If labels seem wrong, remember the confidence score and filter out anything below a threshold like 80 for your app.

Using it from code

This calls Rekognition on an image stored in S3 and prints the labels it finds, with their confidence scores.

import boto3

rekognition = boto3.client("rekognition")

response = rekognition.detect_labels(
    Image={
        "S3Object": {"Bucket": "my-image-bucket", "Name": "photo.jpg"}
    },
    MaxLabels=10,        # return at most 10 labels
    MinConfidence=80,    # ignore anything the model is less than 80% sure about
)

for label in response["Labels"]:
    print(label["Name"], round(label["Confidence"], 1))
Enter fullscreen mode Exit fullscreen mode

Swap detect_labels for detect_moderation_labels to check for unsafe content, or detect_text to read text in the image. The shape of the call stays the same.

Pricing

Item Detail
Image analysis Per image processed, per feature (labels, faces, text, moderation)
Image rate About $1.00 per 1,000 images for common features (US, first tier)
Video analysis Per minute of video processed
Face storage Small monthly charge per 1,000 faces kept in a collection
Volume discounts Lower per unit rates as monthly volume grows
Free tier 5,000 images per month for the first 12 months

The AWS AI services family

AWS AI Services
├── Rekognition   understands images and video
├── Textract      pulls text and data from documents
├── Transcribe    turns speech into text
├── Comprehend    finds meaning and sentiment in text
├── Polly         turns text into speech
└── Translate     translates between languages
Enter fullscreen mode Exit fullscreen mode

These are the ready to use AI services, each solving one problem through a simple API with no model training. Rekognition is the one for vision. Textract, coming later in this series, is the one built specifically for documents.

Wrapping up

Rekognition gives your app eyes. Objects, faces, text, and unsafe content all come back from a single API call, with the machine learning already done for you. Next time a feature needs to understand an image, you know you do not have to build a vision model to get it.

Series progress

You are on stop three of AWS Hidden Gems.

  1. AWS Elemental MediaConvert
  2. Amazon IVS
  3. Amazon Rekognition (you are here)
  4. Amazon Personalize
  5. AWS AppSync
  6. Amazon Timestream
  7. Amazon Textract
  8. Amazon Kendra
  9. AWS DataSync
  10. AWS IoT Core Next up is Amazon Personalize, which builds recommendation systems using the same technology behind Amazon.com, again with no machine learning required.

Let's connect

Questions, corrections, or want to talk through where this fits in your own project? Reach me at khantanseer43@gmail.com.

Top comments (0)