tleyden / eyepi

Object detection on Raspberry Pi with AWS Lambda/S3 backend
2 stars 0 forks source link

eyepi

Security camera object detection software that runs on a Raspberry Pi.

When a person is detected by the model it sends an email/text notification with a 5 second video clip stored on AWS S3.

image

Table of Contents

Requirements

Known security issues

Setup Raspberry Pi (Headless)

Install Eyepi

Clone repo

On the raspberry pi, git clone this repo.

$ git clone git@github.com:tleyden/eyepi.git
$ cd eyepi

Install docker engine

Install docker engine using the convenience script.

Add the pi user to the docker group:

$ sudo usermod -aG docker pi

Build Eyepi Docker image from Dockerfile

$ docker build . -t eyepi

Make sure you can run the docker image:

$ docker run -it --device=/dev/video0:/dev/video0 eyepi eyepi.py --s3bucket eyepi

At this point you should see an error: botocore.exceptions.NoCredentialsError: Unable to locate credentials since you aren't passing in the AWS creds yet. That's covered in a later step.

Setup AWS Cloud

IAM User with S3FullAccess

Create a new IAM User called "eyepi" and associate S3FullAccess permissions. (TODO: limit permissions)

Screen Shot 2021-01-06 at 10 20 29 PM

S3 Bucket

Create a new bucket with a globally unique name - for example <your-email>-eyepi, and settings:

Step 1: Allow public access

Screen Shot 2021-01-06 at 10 25 12 PM

Step 2: Use the default ACL

Screen Shot 2021-01-06 at 10 25 20 PM

SNS topic + subscription

Create a new SNS topic called EyePiNotificationsSNS, and create an email subscription with your email address.

Screen Shot 2021-01-06 at 10 28 29 PM

Lambda function

Step 1: Create a new lambda function from the s3 bucket blueprint

Screen Shot 2021-01-06 at 10 32 03 PM

Step 2: Set function name and role name to EyepiLambda, choose your eyepi s3 bucket for the s3 trigger

Screen Shot 2021-01-06 at 10 33 06 PM

Step 3: Copy the code from lambda-send-sns.py from this repo into the lambda code text area, and hit the "Create" button

Screen Shot 2021-01-06 at 10 33 18 PM

Step 4. Go to the lambda function permission section and click the role

Screen Shot 2021-01-06 at 10 33 51 PM

Step 5: Add the AmazonS3ReadOnlyAccess and AmazonSNSFullAccess policies

Screen Shot 2021-01-06 at 10 34 11 PM

Step 6: In the lambda configuration section, add the SNS ARN as an environment variable called SNS_TOPIC_ARN

Screen Shot 2021-01-06 at 10 41 57 PM

Run eyepi docker container

First set the boto env variables using the access key and secret key for the IAM user created above (without the {}'s):

$ export AWS_ACCESS_KEY_ID="{your-aws-access-key}"
$ export AWS_SECRET_ACCESS_KEY="{your-secret-key}"

Now launch the docker container

$ docker run -it -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --device=/dev/video0:/dev/video0 eyepi eyepi.py --s3bucket <your-bucket-name>

Test it out

You should see output like:

S3 creds OK
read a frame
Frame rate: 1
read a frame
Frame rate: 4.521088120478825

Now walk in front of the camera for a few seconds, and you should see this output:

Person detected!!  Capturing video
read a frame
...
Captured frame 6/5
Finished capturing video, returning to IDLE state
Finished capturing video: /tmp/alert_1610002882.726963.avi
Uploading /tmp/alert_1610002882.726963.avi -> eyepi/alert_1610002882.726963.avi ..
Finished uploading /tmp/alert_1610002882.726963.avi -> eyepi/alert_1610002882.726963.avi ..

and you should receive an email alert with subject "EyePi person detected" and text:

person detected with 0.73828125% confidence. Watch captured video: https://.s3.amazonaws.com/alert_1610002882.726963.avi

Clicking the link on iOS Safari should play it directly.

Run as a daemon process in the background

Kill the docker container previously launched, and re-run and replace the arguments:

-it

with:

-itd

Where the -d tells docker to daemonize the process. It will show the container id, eg: ce43d7b59c, and you can view the logs with:

$ docker logs -f ce43d7b59c

Command Line Args

Name Description Example
s3bucket The name of the s3 bucket to upload capture videos to --s3bucket eyepi
targetobject The object to detect --targetobject mouse
threshold The detection threshold between 0.0 and 1.0 --threshold 0.72
modeldir The directory in the container relative to /root where to look for the model. Can be docker volume mount or absolute path. --modeldir modeldir

Credits

  1. Evan Juras
  2. Adrian Rosebrock

Related projects

References