Description

This project implements a simple computer vision system to detect people in videos using AWS Rekognition. The system processes a video, analyzes selected frames, and generates annotations along with images with and without bounding boxes for each analyzed frame. Then, everything is stored in a new S3 Bucket.

person-detection.drawio (1).png

Requirements

Structure

project/
│   main.py
│   requirements.txt
│   video.mp4
│   README.md

Configuration

First of all, I imported the necessary libraries and created the S3 and Rekognition clients (the most important libraries for this person detection system were boto3 and cv2). Remember to configure your AWS credentials on the CLI to set your access keys and default region .

import io
import boto3
import cv2
import uuid
import logging
from botocore.exceptions import ClientError

# Init AWS clients
s3 = boto3.client('s3')
reko = boto3.client('rekognition')

Development

1. Creating S3 Bucket

To store the data in an S3 Bucket, we need it to be unique across all the other buckets in the AWS cloud, so I used the uuid library to create one.

# create unique s3 bucket
bucket_name = f'aws-person-rekognition-{uuid.uuid4()}'

try:
    s3.create_bucket(Bucket=bucket_name)
except ClientError as e:
    logging.error(e)
except s3.exceptions.BucketAlreadyExists as b:
    logging.error(b)

Unique S3 Bucket

Unique S3 Bucket

2. Selecting Rekognition’s target and video

This is where we need to tell Rekognition which object are we trying to identify. In this case, I chose the ‘Person’ target.