NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

43
Smarten up a Pi Zero Security Camera with Amazon Web Services and Node.js Mark West, Bouvet Oslo

Transcript of NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Page 1: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Smarten up a Pi Zero Security Camera with Amazon Web Services and

Node.jsMark West, Bouvet Oslo

Page 2: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Who Am I?•Manager at Bouvet Oslo.

• Focus on Java, JavaScript, AI, Cloud & the Internet of Things.

• JavaZone organiser.

@markawest

Page 3: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Talk Outline

@markawest

Motivation and

Requirements

Pi Zero Camera

Version 1

Pi Zero Camera

Version 2Conclusion

Page 4: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Motivation and RequirementsInput from Stakeholder

@markawest

Motivation and Requirements

Pi Zero Camera Version 1

Pi Zero Camera Version 2 Conclusion

Page 5: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Motivation

@markawest

Page 6: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Project RequirementsFunctional

•Monitor activity in the garden.

• Send warning when activity detected.

• Live video stream.

Non-functional

• In place as soon as possible.

• Low cost.

• Portable.

@markawest

Page 7: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

1. Activity in garden

2. Camera detects

movement

3. Camera sends alert email with

snapshot

Event Flow to Implement

@markawest

Page 8: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Pi Zero Camera Version 1

Hardware and Activity Detection

@markawest

Motivation and Requirements

Pi Zero Camera Version 1

Pi Zero Camera Version 2 Conclusion

Page 9: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

PiZero Starter Kit: 300kr

Camera Module (NoIR): 250kr

Camera Adapter: 50kr

ZeroView: 80kr

Total Cost: 680kr

Hardware Shopping List

@markawest

Page 10: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Assembled CameraRear View Front View

@markawest

Page 11: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

1. Activity in garden

2. Camera detects

movement

3. Camera sends alert email with

snapshot

Event Flow

@markawest

Page 12: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Motion (https://motion-project.github.io)

• Open Source motion detection software.

• Excellent performance on the Raspberry Pi Zero.

• Built-in Web Server for streaming video.

• Detected activity or ‘motion’ triggers events.

• Works “out of the box”. No need for additional programming.

@markawest

Page 13: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

How Motion Works

@markawest

1 2 3 4

Page 14: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Demo

Pi Zero Camera

Version 1

@markawest

Page 15: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Project Requirements : Evaluation

Functional

•Monitor activity in the garden.

• Send warning when activity detected.

• Live video stream.

Non-functional

• In place as soon as possible.

• Low cost.

• Portable.

@markawest

Page 16: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Example Pictures from Alert Emails

@markawest

Page 17: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Examples of False Positives

@markawest

Page 18: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

The Motion Software focuses on the

amount of changed pixels, and not the

cause of the changed pixels!

@markawest

Page 19: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Pi Zero Camera Version 2

Addressing false positives

@markawest

Motivation and Requirements

Pi Zero Camera Version 1

Pi Zero Camera Version 2 Conclusion

Page 20: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Project Requirements ReloadedFunctional

•Monitor activity in our garden.

• Send warning when activity detected.

• Live video stream.

Non-functional

• In place as soon as possible.

• Low cost.

• Portable.

@markawest

Page 21: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Project Requirements ReloadedFunctional

•Monitor activity in our garden.

• Send warning when human activity detected.

• Live video stream.

Non-functional

• In place as soon as possible.

• Low cost.

• Portable.

@markawest

Page 22: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Finding an Image Analysis Solution

OpenCV

• Use Face Detection to find out if a human was in the snapshot.

• Problem: What if the subject was facing away from the camera, or wearing a mask?

TensorFlow

• Train and use a Neural Network to find humans in the snapshot.

• Rejected by stakeholder as this solution “would take too long to implement”.

@markawest

Page 23: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

@markawest

Page 24: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

AWS Rekognition

@markawest

• Officially launched in November 2016.

• Part of Amazon Web Services (AWS) suite of products.

• Image Analysis as a Service, offering a range of API’s.

• Built on Deep Neural Network models.

• Competitors: Google Vision, MicroSoft Computer Vision and Clarafai.

Page 25: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

AWS Rekognition Demo

@markawest

Page 26: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Limitations of AWS Rekognition

• Black box:• Not always intuitive.• Which labels are we looking for?

• 85% hit rate:• Noisy or blurred images give

worse results.• Possible solution - send multiple

snapshots for each single motion detected event.

@markawest

Page 27: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Updated Event Flow

@markawest

Amazon Web Services (AWS)Trigger Email if

snapshot contains a

person

Analyse snapshot from

Motion software

Tweaked Motion configuration file to provide multiple snapshots for each

detected activity

Page 28: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Demo

Pi Zero Camera

Version 2

@markawest

Page 29: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

AWS IAM

AWS Rekognition

AWS Simple Email Service

AWS s3(storage)

Amazon Web Service FlowOverview

AWS Step Function(workflow)

s3 Upload Trigger

@markawest

1

2

4

5

6

calls

3

uses

uses

Page 30: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

AWS Software Developer Kit (SDK)

• SDK’s exist for a range of platforms – including Python, Ruby, .NET and Java.

• Provide an API for consuming AWS Services.

• For this project I used the Node.js AWS SDK.

• Upload from PiZero Camera to AWS s3 handled by the AWS Node.js SDK.

@markawest

Page 31: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

AWS IAM

AWS s3(storage)

AWS Lambda FunctionsCode Building Blocks or Microservices

AWS Step Function(workflow)

s3 Upload Trigger

@markawest

calls

AWS Rekognition

AWS Simple Email Service

uses

uses

Page 32: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

AWS Lambda Functions• Units of code, based on Java, C#, Python or Node.js

• Serverless.

• Stateless, allowing for rapid scaling as needed.

• High availability.

• “Pay as you go” model, with a generous free tier.

• AWS SDK natively available.

@markawest

Page 33: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

AWS Lambda Demo

@markawest

Page 34: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

AWS IAM

AWS s3(storage)

AWS Step FunctionsOrchestation of Lambda Functions (Microservices)

AWS Step Function(workflow)

s3 Upload Trigger

@markawest

calls

AWS Rekognition

AWS Simple Email Service

uses

uses

Page 35: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

AWS Step Functions• Launched in December 2016.

• Coordinate and orchestrate Lambda Functions into a Workflow or State Machine.

• Defined via JSON files, displayed as visual workflows.

• Provide the same benefits as AWS Lambda (High Availability, Scalable, “Pay as you go” pricing model).

@markawest

Page 36: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Pi Zero Camera v2 : Step Function

@markawest

Error Handler (sends Error Email

via AWS SES)

Sends snapshot to AWS Rekognition

Evaluate AWS Rekognition response

Send Alert Email?

Send Alert Email via AWS SES

Archive image in AWS s3

1

2

3

4

5

61

2

3

4

5

6

Page 37: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

AWS Step Function Demo

@markawest

Page 38: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Estimated AWS CostFirst 12 months

0 kr *

After first 12 months

Less than 50 kr a month *

@markawest

* Estimated cost based on access to AWS Free Tier for first 12 months, with 50 processed images per day

Page 39: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Project Requirements : Evaluation

Functional

•Monitor activity in the garden.

• Send warning when human activity detected.

• Live video stream.

Non-functional

• In place as soon as possible.

• Low cost.

• Portable.

@markawest

Page 40: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Lessons Learned • Hobby projects are still projects.

• Iterative development allows for changing requirements.

• Find creative solutions to cost and time constraints.

• Use The Cloud to push past hardware constraints.

• AWS provides a cheap and easy way to experiment with Cloud Computing, but beware vendor lock-in!

@markawest

Page 41: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Next StepsNight vision Automated deployment

• Round trip for development and test is clunky, especially for Zip Files.

• Look into easing this process.

@markawest

Page 42: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Bouvet Labs

@markawest

Page 43: NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Services and Node.js

Thanks for listening!

markwest1972/smart-security-camera

@markawest

utbrudd.bouvet.no