SlideShare uma empresa Scribd logo
1 de 52
BUILDING A
SMART
SECURITY
CAMERA WITH
PIZERO, JAVA
AND AWS
@markawest
Who Am I?
• IT Consultant at Bouvet.
• Hacker and Maker.
• Java, Data Science, AI/ML.
• Active member of javaBin - the
Norwegian JUG.
@markawestDevExperience
Talk Outline
Motivation
and
Requirements
Building a
Motion
Activated
Camera
Adding Smart
Image Analysis
with AWS
Evaluation and
Tips
@markawestDevExperience
Motivation and Requirements
Input from Stakeholder
Motivation
and
Requirements
Building a
Motion
Activated
Camera
Adding Smart
Image
Analysis with
AWS
Evaluation
and Tips
@markawestDevExperience
Initial Motivation
@markawestDevExperience
Project Requirements
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.
@markawestDevExperience
Functional Design
1. Activity
in garden
2. Camera
detects
movement
3. Camera sends
alert email with
snapshot
@markawestDevExperience
Motivation
and
Requirements
Building a
Motion
Activated
Camera
Adding Smart
Image
Analysis with
AWS
Evaluation
and Tips
Building a Motion Activated
Camera
@markawestDevExperience
Pi Zero W Essentials Kit: $35
Camera Module: $33
Camera Adapter: $7
ZeroView: $10
Total Cost: $85
Hardware Shopping List
@markawestDevExperience
Assembled Camera
Rear View Front View
@markawestDevExperience
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.
@markawestDevExperience
Motion
Streaming
Demo
@markawestDevExperience
How the Motion Software works
1 2 3 4
@markawest
1 2 3
DevExperience
How the Motion Software works
1 2 3 4
1 2 3
@markawest
1 2 3
DevExperience
How the Motion Software works
1 2 3 4
1 2 3
@markawest
1 2 3
DevExperience
Example
Alert Email
1 2
1
@markawestDevExperience
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.
@markawestDevExperience
False Alarms from Web Camera
cat
cloud
@markawestDevExperience
The Motion Software
focuses on the amount of
changed pixels, and not the
cause of the changed
pixels!
@markawestDevExperience
Motivation
and
Requirements
Building a
Motion
Activated
Camera
Adding Smart
Image
Analysis with
AWS
Evaluation
and Tips
Adding Smart Image Analysis
with AWS
@markawestDevExperience
Improving Alarm Accuracy with
Smart Image Analysis
person
@markawest
cat
DevExperience
Project Requirements Reloaded
Functional
• Monitor activity in our
garden.
• Send warning when activity
detected.
• Live video stream.
Non-functional
• In place as soon as possible.
• Low cost.
• Portable.
@markawestDevExperience
Project Requirements Reloaded
Functional
• 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.
@markawestDevExperience
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.
• Problem: Potentially a fun
project, but would take more
time than I had available.
@markawestDevExperience
AWS Rekognition
• Part of Amazon Web Services suite of Cloud based services.
• Image Analysis as a Service, offering a range of API’s.
• Built upon Deep Neural Networks.
• Officially launched in November 2016.
• Alternatives: Google Vision, MicroSoft Computer Vision, Clarafai.
@markawestDevExperience
AWS Rekognition Demo
@markawestDevExperience
Adding AWS to the Web Camera
Amazon Web Services (AWS)
Send warning
email (if snapshot
contains a person)
Snapshot analysed
via AWS
Rekognition
@markawest
Camera pushes
snapshot to AWS
Email alert sent
(with snapshot)
DevExperience
AWS IAM
AWS
Rekognition
AWS Simple
Email Service
AWS S3
(storage)
Amazon Web Service Flow
Overview
AWS Step Function
(workflow)
Upload
Trigger
1
2
4
5
6
calls
3
uses
uses
@markawestDevExperience
AWS IAM
AWS
Rekognition
AWS Simple
Email Service
AWS S3
(storage)
AWS Lambda Functions
Code Building Blocks (aka Microservices)
AWS Step Function
(workflow)
Upload
Trigger calls
uses
uses
@markawestDevExperience
AWS Lambda Functions
• Code units based on Java, C#, Go, Python or Node.js
• Serverless, no infrastructure to manage.
• Highly available and highly scalable.
• Pay as you go model based on total invocations and duration - with a
generous Free Tier.
• Native AWS SDK gives easy access to other AWS services.
@markawestDevExperience
AWS Lambda Demo
@markawestDevExperience
AWS IAM
AWS S3
(storage)
AWS Step Functions
Orchestration of Lambda Functions
AWS Step Function
(workflow)
Upload
Trigger calls
AWS
Rekognition
AWS Simple
Email Service
uses
uses
@markawestDevExperience
AWS Step Functions
• Coordinate and orchestrate Lambda Functions into Workflows or
State Machines.
• Launched in December 2016.
• Defined via JSON files, displayed as visual workflows.
• Provide the same benefits as AWS Lambda (High Availability,
Serverless, Scalable, “Pay as you go” pricing model).
@markawestDevExperience
Step Function for Image Processing
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
6 1
2
3
4
5
6
@markawestDevExperience
Smart Camera
(and AWS Step Function)
Demo
@markawestDevExperience
Motivation
and
Requirements
Building a
Motion
Activated
Camera
Adding Smart
Image
Analysis with
AWS
Evaluation
and Tips
Evaluation and Lessons
Learned
@markawestDevExperience
DevExperience
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
AWS Rekognition : The Positives
• Consistent results.
• Successfully handles ’partial’ images.
• Handles poor quality images (motion
blur, poor lighting).
• No more false alarms.
@markawestDevExperience
AWS Rekognition : Some Negatives
• Black box.
• Unable to provide feedback.
• Struggles with ‘noisy’ pictures.
• Results are only as good as the pictures
you upload (resulting in a 80-95% hit
rate).
@markawestDevExperience
Activity Timeline
@markawest
Activity
Event
Start
1 Activity
Event
Stop
2 3 4 5
Which Image Should Motion Upload?
DevExperience
Activity Timeline
@markawest
Activity
Event
Start
1 Activity
Event
Stop
2 3 4 5
First
Picture
Which Image Should Motion Upload?
DevExperience
Activity Timeline
@markawest
Activity
Event
Start
1 Activity
Event
Stop
2 3 4 5
Most
Pixels
Changed
Which Image Should Motion Upload?
DevExperience
Activity Timeline
@markawest
Activity
Event
Start
1 Activity
Event
Stop
2 3 4 5
Most
Central
Activity
Which Image Should Motion Upload?
DevExperience
Activity Timeline
@markawest
Activity
Event
Start
1 Activity
Event
Stop
2 3 4 5
Upload all snapshots
Which Image Should Motion Upload?
DevExperience
Improving AWS Rekognition Hit Rate
Upload One Snapshot
when activity detected
• Lower cost, due to less calls
to the AWS stack.
• Potentially lower hit rate.
Upload Many Snapshots
when activity detected
• Higher cost due to
increased calls to the AWS
stack.
• Potentially higher hit rate.
@markawestDevExperience
Cost : April 2018
@markawest
Rekognition:
$8.09
SES: $0.01
S3: $0.70
Step
Functions:
$0.98
VAT: $2.45
(Based on 7050 images processed)
Lambda: $0.00
DevExperience
“Fun project, but has it
caught any real criminals?”
@markawestDevExperience
Next Steps?
OpenCV + Deep Learning
• OpenCV 3.1 added support for
pre-trained DNN models.
• Supports Caffe, TensorFlow
and Torch.
• Proven to work on Pi3.
Rekognition Video
• Introduced in November 2017.
• Real time analysis of streaming
video (via AWS Kinesis).
• 1000 minutes of video free per
month (first year only).
@markawestDevExperience
Would you like to know more?
github.com/markwest1972/
smart-security-camera
@markawest
Code & Instructions for replicating project
Links to Blog Entries describing project
The Heisencat by Jon Rohan
DevExperience
FOR
LISTENING!
@markawest
Kraków, 17-19 May 2017

Mais conteúdo relacionado

Mais procurados

Mais procurados (14)

I Love APIs Europe 2015: Developer Sessions
I Love APIs Europe 2015: Developer SessionsI Love APIs Europe 2015: Developer Sessions
I Love APIs Europe 2015: Developer Sessions
 
Nakal
NakalNakal
Nakal
 
OOP 2016 - Building Software That Eats The World
OOP 2016 - Building Software That Eats The WorldOOP 2016 - Building Software That Eats The World
OOP 2016 - Building Software That Eats The World
 
AtlasCamp 2015: Getting your Connect add-on over the finish line
AtlasCamp 2015: Getting your Connect add-on over the finish lineAtlasCamp 2015: Getting your Connect add-on over the finish line
AtlasCamp 2015: Getting your Connect add-on over the finish line
 
AtlasCamp 2015: Damn you Facebook - Raising the bar in SaaS
AtlasCamp 2015: Damn you Facebook - Raising the bar in SaaSAtlasCamp 2015: Damn you Facebook - Raising the bar in SaaS
AtlasCamp 2015: Damn you Facebook - Raising the bar in SaaS
 
AtlasCamp 2015: Game of Codes: The CI battle
AtlasCamp 2015: Game of Codes: The CI battleAtlasCamp 2015: Game of Codes: The CI battle
AtlasCamp 2015: Game of Codes: The CI battle
 
AtlasCamp 2015 Keynote
AtlasCamp 2015 KeynoteAtlasCamp 2015 Keynote
AtlasCamp 2015 Keynote
 
Is Serverless The New Swiss Cheese?
Is Serverless The New Swiss Cheese?Is Serverless The New Swiss Cheese?
Is Serverless The New Swiss Cheese?
 
Custom vision
Custom visionCustom vision
Custom vision
 
Accelerating Add-on Development From Concept to Launch
Accelerating Add-on Development From Concept to LaunchAccelerating Add-on Development From Concept to Launch
Accelerating Add-on Development From Concept to Launch
 
Introducing to serverless computing and AWS lambda - Israel Clouds Meetup
Introducing to serverless computing and AWS lambda - Israel Clouds MeetupIntroducing to serverless computing and AWS lambda - Israel Clouds Meetup
Introducing to serverless computing and AWS lambda - Israel Clouds Meetup
 
Adapting Java for the Serverless World at JUG Barcelona
Adapting Java for the Serverless World at JUG BarcelonaAdapting Java for the Serverless World at JUG Barcelona
Adapting Java for the Serverless World at JUG Barcelona
 
Serverless Meetup - 12 gennaio 2017
Serverless Meetup - 12 gennaio 2017Serverless Meetup - 12 gennaio 2017
Serverless Meetup - 12 gennaio 2017
 
AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Anahe...
AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Anahe...AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Anahe...
AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Anahe...
 

Semelhante a DevExperience 2018 : Building a Smart Security Camera with Raspberry Pi Zero, Java and AWS

End to End Testing with nightwatchjs
End to End  Testing with nightwatchjsEnd to End  Testing with nightwatchjs
End to End Testing with nightwatchjs
Srikanth Madduri
 

Semelhante a DevExperience 2018 : Building a Smart Security Camera with Raspberry Pi Zero, Java and AWS (20)

JavaZone 2017 : Building a smart security camera with raspberry pi zero, java...
JavaZone 2017 : Building a smart security camera with raspberry pi zero, java...JavaZone 2017 : Building a smart security camera with raspberry pi zero, java...
JavaZone 2017 : Building a smart security camera with raspberry pi zero, java...
 
Riga Dev Days: Building a Smart Security Camera with Raspberry Pi Zero, Node....
Riga Dev Days: Building a Smart Security Camera with Raspberry Pi Zero, Node....Riga Dev Days: Building a Smart Security Camera with Raspberry Pi Zero, Node....
Riga Dev Days: Building a Smart Security Camera with Raspberry Pi Zero, Node....
 
GeeCon 2017 : Building a Smart Security Camera with Raspberry Pi Zero, Node.j...
GeeCon 2017 : Building a Smart Security Camera with Raspberry Pi Zero, Node.j...GeeCon 2017 : Building a Smart Security Camera with Raspberry Pi Zero, Node.j...
GeeCon 2017 : Building a Smart Security Camera with Raspberry Pi Zero, Node.j...
 
Make Data Smart Again 2018 - Building a Smart Security Camera with Raspberry ...
Make Data Smart Again 2018 - Building a Smart Security Camera with Raspberry ...Make Data Smart Again 2018 - Building a Smart Security Camera with Raspberry ...
Make Data Smart Again 2018 - Building a Smart Security Camera with Raspberry ...
 
NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Ser...
NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Ser...NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Ser...
NTNU Tech Talks : Smartening up a Pi Zero Security Camera with Amazon Web Ser...
 
GeeCON Prague : Building a Smart Security Camera with Raspberry Pi Zero, Java...
GeeCON Prague : Building a Smart Security Camera with Raspberry Pi Zero, Java...GeeCON Prague : Building a Smart Security Camera with Raspberry Pi Zero, Java...
GeeCON Prague : Building a Smart Security Camera with Raspberry Pi Zero, Java...
 
IoT Meetup Oslo - AI on Edge Devices
IoT Meetup Oslo - AI on Edge DevicesIoT Meetup Oslo - AI on Edge Devices
IoT Meetup Oslo - AI on Edge Devices
 
IoT Tech Day Smart Camera slides. Utrecht, April 2017.
IoT Tech Day Smart Camera slides.  Utrecht, April 2017.IoT Tech Day Smart Camera slides.  Utrecht, April 2017.
IoT Tech Day Smart Camera slides. Utrecht, April 2017.
 
Serverless Culture
Serverless CultureServerless Culture
Serverless Culture
 
Surviving Serverless Testing: The ultimate Guide
Surviving Serverless Testing: The ultimate GuideSurviving Serverless Testing: The ultimate Guide
Surviving Serverless Testing: The ultimate Guide
 
Ohio Devfest - Visual Analysis with GCP
Ohio Devfest - Visual Analysis with GCPOhio Devfest - Visual Analysis with GCP
Ohio Devfest - Visual Analysis with GCP
 
Getting Started with Serverless Architectures using Azure Functions
Getting Started with Serverless Architectures using Azure FunctionsGetting Started with Serverless Architectures using Azure Functions
Getting Started with Serverless Architectures using Azure Functions
 
End to End Testing with nightwatchjs
End to End  Testing with nightwatchjsEnd to End  Testing with nightwatchjs
End to End Testing with nightwatchjs
 
Nightwatch JS for End to End Tests
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End Tests
 
SRV318_Research at PNNL Powered by AWS
SRV318_Research at PNNL Powered by AWSSRV318_Research at PNNL Powered by AWS
SRV318_Research at PNNL Powered by AWS
 
Research at PNNL: Powered by AWS - SRV318 - re:Invent 2017
Research at PNNL: Powered by AWS - SRV318 - re:Invent 2017Research at PNNL: Powered by AWS - SRV318 - re:Invent 2017
Research at PNNL: Powered by AWS - SRV318 - re:Invent 2017
 
Unity and Microsoft Azure Cognitive Services - DIGITREK21 Workshop
Unity and Microsoft Azure Cognitive Services - DIGITREK21 WorkshopUnity and Microsoft Azure Cognitive Services - DIGITREK21 Workshop
Unity and Microsoft Azure Cognitive Services - DIGITREK21 Workshop
 
Rails in the Cloud
Rails in the CloudRails in the Cloud
Rails in the Cloud
 
Building real time image classifiers for mobile apps with azure custom vision
Building real time image classifiers for mobile apps with azure custom visionBuilding real time image classifiers for mobile apps with azure custom vision
Building real time image classifiers for mobile apps with azure custom vision
 
Yow Conference Dec 2013 Netflix Workshop Slides with Notes
Yow Conference Dec 2013 Netflix Workshop Slides with NotesYow Conference Dec 2013 Netflix Workshop Slides with Notes
Yow Conference Dec 2013 Netflix Workshop Slides with Notes
 

Mais de Mark West

Mais de Mark West (10)

A Practical-ish Introduction to Data Science
A Practical-ish Introduction to Data ScienceA Practical-ish Introduction to Data Science
A Practical-ish Introduction to Data Science
 
Explaining the new Java release and licensing models
Explaining the new Java release and licensing modelsExplaining the new Java release and licensing models
Explaining the new Java release and licensing models
 
GeeCon Prague 2018 - A Practical-ish Introduction to Data Science
GeeCon Prague 2018 - A Practical-ish Introduction to Data ScienceGeeCon Prague 2018 - A Practical-ish Introduction to Data Science
GeeCon Prague 2018 - A Practical-ish Introduction to Data Science
 
JavaZone 2018 - A Practical(ish) Introduction to Data Science
JavaZone 2018 - A Practical(ish) Introduction to Data ScienceJavaZone 2018 - A Practical(ish) Introduction to Data Science
JavaZone 2018 - A Practical(ish) Introduction to Data Science
 
NDC Oslo : A Practical Introduction to Data Science
NDC Oslo : A Practical Introduction to Data ScienceNDC Oslo : A Practical Introduction to Data Science
NDC Oslo : A Practical Introduction to Data Science
 
JavaZone 2016 : MQTT and CoAP for the Java Developer
JavaZone 2016 : MQTT and CoAP for the Java DeveloperJavaZone 2016 : MQTT and CoAP for the Java Developer
JavaZone 2016 : MQTT and CoAP for the Java Developer
 
JavaZone 2015 : NodeBots - JavaScript Powered Robots with Johnny-Five
JavaZone 2015 : NodeBots - JavaScript Powered Robots with Johnny-FiveJavaZone 2015 : NodeBots - JavaScript Powered Robots with Johnny-Five
JavaZone 2015 : NodeBots - JavaScript Powered Robots with Johnny-Five
 
Coding Mojo : Node.js Meetup
Coding Mojo : Node.js MeetupCoding Mojo : Node.js Meetup
Coding Mojo : Node.js Meetup
 
IoT Tech Day Coding Mojo slides. Utrecht, April 2016
IoT Tech Day Coding Mojo slides.  Utrecht, April 2016IoT Tech Day Coding Mojo slides.  Utrecht, April 2016
IoT Tech Day Coding Mojo slides. Utrecht, April 2016
 
JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics ...
JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics ...JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics ...
JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics ...
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

DevExperience 2018 : Building a Smart Security Camera with Raspberry Pi Zero, Java and AWS

Notas do Editor

  1. But before I go any further I’d like to tell you a couple of things about me. In my day job I am a manager in Bouvet’s Oslo offices, where I work with a range of technologies based upon Java and JavaScript. My current focus is upon AI, Cloud and the Internet of Things. When I’m not at work I can often be found working on a range of hobby projects – often using the Raspberry Pi and Arduino platforms. In addition I am also involved in the organisation of the JavaZone conference, where I primarily work with the program committee. I’m on twitter under the handle @markawest, so feel free to contact me if there is anything you’d like to talk about!
  2. Ok, so lets look at the outline of todays talk. We’ll start in a second with a run through of the motivation for building this camera, along with the requirements. These should always be clear and defined for any project, whether it is a multi million kroner project for NAV, or a hobby project undertaken by an englishman living in Oslo. Then we’ll look at the first version of the camera, evaluate how it worked and discuss it’s weaknesses. The second version of the camera is where we introduce Amazon Web Services to the mix and will take up the majority of the presentation time. Finally I’ll evaluate the project and talk about what I learned.
  3. Ok, so lets get started by looking at why I did this project!
  4. The motivation for creating my camera was simple enough. A large amount of break-ins had recently taken plan in the area where I live. The thieves targeted houses with secluded gardens, as the chance of being spotted by passers by was lower. My garden is not visible from the road, making it a prime target for the thieves.
  5. When undertaking any project you need to identify the stakeholders, or those who will be affected by the project outcome. These stakeholders will have their expectations of the project, and your requirements should always take the stakeholders expectations into account. For this project my wife was my primary stakeholder, so the requirements reflected her wishes. (Go through requirements)
  6. Once I’d gathered the requirements I realized that I needed to implement the above, in a cost effective and speedy manner.
  7. Ok, so lets get started by looking at why I did this project!
  8. Approx 5000 RUB. $1 = 60 RUB? We’ll begin by looking at the hardware I used for creating the Camera and how much this costs. The Pi Zero is a cut down version of the Raspberry Pi. They cost about 50kr, but you’ll also need to buy an SD card, power supply and HDMI and USB adapters. Therefore I recommend a starter kit such as the one sold by the Pi Hut. This costs 300 kr, and gives you all you need to get started with the Pi Zero. In addition to the Pi Zero board I needed a camera. I choose the Raspberry Pi Camera module, at around 250 kr. To fit this to the Pi Zero I also had to buy a Pi Zero Camera adapter, which cost an additional 50 kr. The camera I chose was the Pi NoIR, which work better in low conditions. To truly provide night vision it requires an IR light source, which I didn’t buy for this project. Finally I needed a mount for the Camera. I choose the ZeroView at 80 kr. The total cost for all equipment (if bought new) would be therefore approximately 680kr. If this seems a lot of money, remember that you can easily reuse the components for other projects at a later point!
  9. Here you can see the fully assembled camera, from the front and the back. The white cable is a USB Wi Fi adapter and the black cable is for power.
  10. Once I’d gathered the requirements I realized that I needed to implement the above, in a cost effective and speedy manner.
  11. After some consideration, I decided to use the Linux Motion software. Motion is open source, and is purpose built for motion detection. It has excellent performance on the Raspberry Pi Zero, plus a built in web server for streaming video. Detected activity triggers an “event” in Motion, which can be used to send email alerts. Motion works out of the box and is highly configurable. With no need for additional programming it would take no time at all to get up and running.
  12. So how does Motion work? Well it basically monitors the video stream from the camera. Each frame is compared to the previous, in order to find out how many pixels (if any) differ. If the total number of changed pixels is greater than a given threshold, a motion alarm is then triggered.
  13. So how does Motion work? Well it basically monitors the video stream from the camera. Each frame is compared to the previous, in order to find out how many pixels (if any) differ. If the total number of changed pixels is greater than a given threshold, a motion alarm is then triggered.
  14. So how does Motion work? Well it basically monitors the video stream from the camera. Each frame is compared to the previous, in order to find out how many pixels (if any) differ. If the total number of changed pixels is greater than a given threshold, a motion alarm is then triggered.
  15. So how does Motion work? Well it basically monitors the video stream from the camera. Each frame is compared to the previous, in order to find out how many pixels (if any) differ. If the total number of changed pixels is greater than a given threshold, a motion alarm is then triggered.
  16. I was initially very happy with the first version of the Pi Zero Camera. The camera monitored my garden for the whole of July, whilst I was in England with my family. The results from the camera were quite boring, and mostly showed the neighbor's watering our flowers, plus me testing out the camera before we left.
  17. Ok, lets revisit my project requirements. My camera: Would monitor activity in the garden. It would be able to send an email when acitivity was detected. It included a live video stream. It was quick to build and program. It had a one of cost of 680kr. And it was portable. All this led to a happy stakeholder! But was the project completely successful?
  18. False alerts : why problematic? Loads of emails, that’s why!
  19. Ok, let us try a quick demo of the Pi Camera Version 1.
  20. Ok, so lets get started by looking at why I did this project!
  21. You’ll remember these project requirements from earlier on in this presentation. Lets just revisit them all! They are all still just as relevant. But by adding one word to one of the functional requirements we can address the issue of false positives. Any guesses?
  22. Yep. The missing word is “Human”! We only want to send warnings when human activity is detected.
  23. At this point I realised that I had to find an Image Analysis solution. My first idea was to use OpenCV to perform Face Detection on the snapshot images. <click> This type of use of OpenCV is well proven and well documented, and wouldn’t take long to implement. <click> However, it would only work if the subject was facing the camera, and wasn’t wearing a mask! <click> My next idea was to use Googles TensorFlow. This would allow me to create and train a neural network to analyse my images. <click> The downside here is that it would take a considerable investment of time for me to get up and running. This idea was therefore vetoed by my primary stakeholder, who wanted a solution as quick as possible.
  24. Luckily the solution presented itself to me through a random tweet in my twitter feed. <click> It turned out that Arun was talking about Amazon Rekognition, a new Image Analysis solution.
  25. Why cloud based?
  26. Perhaps the best way of understanding what Amazon Rekognition is, is to run a quick demo. DetectLabels use Burglar picture from NTNU folder on my Desktop.
  27. My next challenge was to find out how I would trigger the image processing from my Pi Zero Camera. After some thought I decided to move the whole image processing and email handling to The Cloud, and specifically Amazon Web Services. My planned solution basically looked as follows: The PiZero Camera monitors the garden. On detecting movement, a snapshot is taken and pushed to Amazon Web Services. Amazon web services handles the image analysis and the eventual sending of an alert emails. This solution had some benefits: 1. The Pi Zero could now focus on running the motion software. 2. The Camera and Image Processing would be seperated, making it easy to replace either at a later date. I also tweaked the Motion configuration file to provide multiple snapshots for each detected activity. More pictures would increase the chance of Motion correctly detecting movement.
  28. Ok, so how did the AWS processing work? Here’s a simplified run through. Firstly an image is pushed from the PiZero Camera to Amazon’s s3 storage. A small unit of code or Lambda Function is triggered by the upload. It in turn triggers a Step Function. The Step Function orchestrates further Lambda Functions into a workshop. The first Lambda Function makes a call to Rekognition to evaluate the picture. The second Lambda Function uses the Simple Email Service to send the alert email. Finally, all components in the workflow use Identity Access management to make sure that they have access to the components they need to use. For example, the Lambda Function that sends an email needs access to both the Simple Email Service and to s3 in order to attach the image file to the email
  29. On upload to s3, a Lambda Function is triggered, which in turn triggers a step function, which contains more Lambda Functions. Lets look at AWS Lambda Functions and their role in our solution.
  30. A Lambda Function is essentially a unit of code. As today it is possible to implement Lambda Function using Java, C#, Python and Node.js. Lamba Functions are serverless. This doesn’t mean that they run without servers, but that the business or person running the code doesn’t have to worry about provisioning or managing the servers. In other word, Amazon has responsibility for making sure that the servers are up and running. Lambda Functions are also stateless. By not storing state they are more easily scaled up and down. This scalability is an important part of the Cloud paradigm, as it allows one to scale Lambda Functions rapidly up and down according to demand. The AWS Lambda platform is engineered to be highly available, making it suitable for running applications that need to be up all of the time. AWS Lambda utilises a Pay as you go model. This means that you pay only for the processing time you use. This means that an application with low traffic will be relatively cheap compared to one with lots of traffic. ASW Lambda also has a free tier for those who want to get started with AWS. This provides free usage up to a given threshold. AWS Lambda also has the SDK natively available, making it simple to call other AWS services and resources.
  31. { "s3Bucket": "smart-security-camera-upload", "sendAlert": false, "rekognitionLabels": {}, "s3ArchivedKey": null, "stepFunctionID": "60331694-7476-43c8-b866-8f0ca3d9db2e", "s3key": "archive/falsepositives/gardenCam1/20170904/131601-6069-01.jpg” }
  32. On upload to s3, a Lambda Function is triggered, which in turn triggers a step function, which contains more Lambda Functions. Lets look at AWS Lambda Functions and their role in our solution.
  33. Here is the actual Step Function for my Camera, rendered by the AWS Step Function interface. It’s not necessarily easy to see the flow here, so let me try to shed some light on how this works. The first step submits the snapshot to AWS Rekognition. The second step then evaluates the response from AWS Rekognition. It looks for labels such as “Person” and ”Human” and sets a flag to indicate whether a person has been found. The third step uses this flag to decide whether or not to send an email. Unlike all the other steps this is not calling a Lambda Function. The fourth step sends the alert email if. This will be skipped if the alert flag is set to false. The fifth step archives the snapshot – either in an alert folder or a false positive folder. The final step is an all purpose error handler. Any errors during processing will result in an email being sent to me.
  34. Ok, let us try a quick demo of the Pi Camera Version 2. Show happy case and unhappy case. Show Step Function flow If camera NOT working, try upload from PC : cd '/Users/mark.west/Documents/GitHub Repositories/smart-security-camera/s3-upload/' s3-upload mark.west$ node s3-upload-image-file.js smart-security-camera-upload /Users/mark.west/Desktop/ntnu/burglar.png
  35. Ok, so lets get started by looking at why I did this project!
  36. Ok, lets revisit my project requirements. My camera: Would monitor activity in the garden. It would be able to send an email when human activity was detected. It included a live video stream. It was quick to build and program. It had a one of cost of 680kr. And a yearly cost of 600kr after the first year. And it was portable. All this led to a happy stakeholder! But was the project completely successful?
  37. VAT is 23-25% from what I can see. Some services have a level of free usage for the first year. For example Rekognition allows 5000 pictures a month. S3 also has a certain amount of free usage for the first year. I’m still in my first year, but from December 2017 my monthly price rose by about 5 dollars a month, including tax. This is mainly because I now pay $1 per 1000 Images Processed, whereas before I got the first 5000 images free. The other costs are more or less comparable with those I paidin my first year. Note that I don’t pay anything for Lambda Function usage – my usage is well under the thresholds for billing.
  38. Ok, let us try a quick demo of the Pi Camera Version 1.
  39. The first figure is based on usage in March, where approximately 3750 images where processed – approximately 125 a day. During this period I received less than 100 real alarms. The second figure is based on the same usage amounts once the free tier is expired. The extra costs will mostly arise from costs of Step Functions and Rekognition, which as new services come at a premium rate. Other than that, additional costs will be incurred by S3 usage.
  40. Ca. 10 cents per minute of video analysed, plus kinesis and possibily S3 charges.
  41. Thanks very much for attending my talk! You can find more information about this project at the Bouvet blog. And you’ll find all the code on my GitHub. If anyone wants to have a chat I’ll be on the Bouvet stand for the rest of the day and will be joining some of you for food this evening!