SlideShare a Scribd company logo
girlie_mac@
KittyCam.js
Smile, you’re on camera!Smile, you’re on camera!
Tomomi Imura
girlie_mac@
Hello, I’m Tomomi & I’m a:
● San Francisco Dweller
● Front-End Engineer
● Open Web + Tech Advocate
● N00b Hardware Hacker
● Sr. Developer Advocate at Nexmo
● Cat lady of InterWeb
girlie_mac@
girlie_mac@
CC-BY-SA 3.0
https://commons.wikimedia.org/wiki/File:Basic_robot.jpg
girlie_mac@
Arduino
● MCU-based kit
● Open-Source hardware &
software (IDE)
● The first developer-friendly
boards
girlie_mac@
Sketch
● Language for Arduino
● Loosely based on C
● Wut, C?
● HALP!!1!!!
#include <Servo.h>
#include <Wire.h>
#include <Firmata.h>
#define I2C_WRITE B00000000
#define I2C_READ B00001000
#define I2C_READ_CONTINUOUSLY B00010000
#define I2C_STOP_READING B00011000
#define I2C_READ_WRITE_MODE_MASK B00011000
#define I2C_10BIT_ADDRESS_MODE_MASK B00100000
#define I2C_MAX_QUERIES 8
#define I2C_REGISTER_NOT_SPECIFIED -1
#define MINIMUM_SAMPLING_INTERVAL 1
int analogInputsToReport = 0;
byte previousPINs[TOTAL_PORTS];
byte pinConfig[TOTAL_PINS];
byte portConfigInputs[TOTAL_PORTS];
int pinState[TOTAL_PINS];
unsigned long currentMillis;
girlie_mac@
Raspberry Pi
● $35 single-board computer
● Broadcom chip with
ARM-compatible CPU & GPU
● Runs Linux
● More language choices: C,
C++, Python...
girlie_mac@
But… I want to code in
girlie_mac@
Johnny-Five
● JavaScript robotics framework
● Works with
Arduino-compatible Boards
● IO plugins for more platform
supports
● http://johnny-five.io/
girlie_mac@
Awww, JavaScript all the way!
girlie_mac@
Hello world!
girlie_mac@
KittyCam
Raspberry Pi camera with cat facial
detection!
● Hardware: Raspberry Pi, camera, and PIR
sensor
● Software: Node.js + J5 + More
open-source goodies
girlie_mac@
Motion detected!
snap!
Mmm… donut
girlie_mac@
kittyCam.js
1. Detect motion
2. Take a photo
3. Cat facial detection
4. Store the photo in cloud
5. Real-time view on web
6. SMS the photo link
HELL,
YEAH!
girlie_mac@
girlie_mac@
Raspberry Pi 3
PIR Motion Sensor
Camera Module
F/F Jumper Wires (x3)
girlie_mac@
girlie_mac@
girlie_mac@
1. Raspberry Pi 3
2. 5MP Camera
Board Module
3. Pyroelectric
Infrared (PIR)
motion sensor
4. Female/Female
wires
girlie_mac@
Programming Raspberry Pi
Pre-installed on Raspbian OS:
C /
C++
girlie_mac@
Programming RPi with Node.js
girlie_mac@
girlie_mac@
Installing Node ARM
$ wget
https://nodejs.org/dist/v4.4.5/node-v4.4.5-l
inux-armv7l.tar.xz
$ tar -xvf node-v4.4.5-linux-armv7l.tar.xz
$ cd node-v4.4.5-linux-armv7l
$ sudo cp -R * /usr/local/
girlie_mac@
kittyCam.js
1. Detect motion
2. Take a photo
3. Cat facial detection
4. Store the photo in cloud
5. Real-time view on web
6. SMS the photo link
HELL,
YEAH!
girlie_mac@
kittyCam.js Tech Stack
1. Detect motion w/ Johnny-Five IR.Motion obj
2. Take a photo w/ Raspistill, command line tool
3. Cat facial detection w/ KittyDar
4. Store the photo in Cloudinary
5. Publish & subscribe the url to display on web
via PubNub
6. Send a text message via Nexmo
girlie_mac@
$ Raspistill
canvas
catDetect.js
app.js
kittyDar
Motion detected
take a photo
Store the photo if cats are detected
display photos on web browsers
real-time anywhere
Johnny-Five
w/ raspi-io
child
process
Returns url
Notify with SMS via
girlie_mac@
Johnny-Five w/ Raspi-io
const five = require('johnny-five');
const raspi = require('raspi-io');
let board = new five.Board({io: new raspi()});
board.on('ready', () => {
console.log('board is ready');
...
});
girlie_mac@
Motion
const five = require('johnny-five');
const raspi = require('raspi-io');
const board = new five.Board({io: new raspi()});
board.on('ready', function() {
// Create a new `motion` hardware instance
const motion = new five.Motion('P1-7');
...
});
a PIR is wired on pin 7
(GPIO 4)
VCC
Ground
Data
girlie_mac@
Raspistill Command Line Tool
$ raspistill -o myPhoto.jpg
girlie_mac@
PIR Sensor > Run Camera
const child_process = require('child_process');
board.on('ready', () => {
const motion = new five.Motion('P1-7');
motion.on('motionstart', () => { // Motion detected
let filename = 'photo/image_'+i+'.jpg';
let args = ['-w', '320', '-h', '240', '-o', filename, '-t', '1'];
let spawn = child_process.spawn('raspistill', args);
spawn.on('exit', function() {
console.log('A photo is saved as '+filename);
...
motion
detected!
Take a photo!
Spawns a new process w/ a given shell command
girlie_mac@
Processing Image
spawn.on('exit', () => {
let imgPath = __dirname + '/' + filename;
// Child process: read the file and detect cats with KittyDar
let args = [imgPath];
let fork = child_process.fork(__dirname+'/detectCatsFromPhoto.js');
fork.send(args);
// the child process is completed
fork.on('message', (base64) => {
if(base64) {
uploadToCloud(base64); // Send to cloud storage
}
}); ...
Create another worker
by running a new
instance of V8 engine.
girlie_mac@
detectCatsFromPhoto.js
const kittydar = require('kittydar');
const Canvas = require('canvas');
process.on('message', (m) => {
fs.readFile(m[0], (err, data) => {
...
let canvas = new Canvas(w, h);
let ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, w, h, 0, 0, w, h);
let cats = kittydar.detectCats(canvas);
console.log('There are', cats.length, 'cats in this photo');
if(cats.length > 0) {base64Img = canvas.toDataURL();}
process.send(base64Img);
process.exit(0);
});
Running in an another process
a cat detected!
KittyDar
girlie_mac@
KittyDar
● Open-source JavaScript cat facial
detection written by Heather Arthur
● Takes a canvas obj & calculate the
locations of cats in the image
let cats = kittydar.detectCats(canvas);
girlie_mac@
KittyDar: Behind the Scene
1. Chops up the image up into many “windows”
2. Extracts data by measuring a set of gradients,
from light & dark in order to find edges
3. Compares the direction of these edges to the
edges found in known cat images
Neural network (JSON w/ vector data) is
pre-trained w/ thousands pics of cats & non-cats
girlie_mac@
Cat Facial Detection
http://research.microsoft.com/pubs/80582/ECCV_CAT_PROC.pdf
girlie_mac@
Cat Facial Detection
http://research.microsoft.com/pubs/80582/ECCV_CAT_PROC.pdf
girlie_mac@
Cat Facial Detection
The annotation data sequence:
(Number of points, default is 9), (Left Eye), (Right
Eye), (Mouth), (Left Ear-1), (Left Ear-2), (Left Ear-3),
(Right Ear-1), (Right Ear-2), and (Right Ear-3)
girlie_mac@
Cat Facial Data
9 247 94 294 92 273
127 213 81 207 29
247 53 286 50 320
20 322 74
00000561_012.jpg.cat00000561_012.jpg
girlie_mac@
Cat Facial Data Collection
girlie_mac@
Neural Network
Positive
Negative
JSON data
hog-descriptor
kittydar.jsCompare data
girlie_mac@
Send the Pic w/ Kitty to Cloud
const cloudinary = require('cloudinary');
// the child process is completed
fork.on('message', (base64) => {
if(base64) {
cloudinary.uploader.upload(base64, (result) => {
// Done! - Get the URL and do more stuff
});
} else deletePhoto(imgPath);
});
girlie_mac@
View Photos Real-time via Socket
const pubnub = require(pubnub);
Publish Subscribe
girlie_mac@
http://www.girliemac.com/RPi-KittyCam/
girlie_mac@
Send SMS via Nexmo
const Nexmo = require(nexmo);
let nexmo = new Nexmo({//config with API keys});
nexmo.message.sendSms(
FROM_NUMBER, TO_NUMBER, ' '+ url, options,
(err, responseData) => {
if (err) console.log(err);
else console.dir(responseData);
});
girlie_mac@
girlie_mac@
QA Team
Lead QA:
Jamie
Ginger Basil Alice Yugi Venom
@kittenVenom
Ozzy
girlie_mac@
github.com/girliemac/RPi-KittyCam
girlie_mac@
Next Steps
● Upgrade Hardware
○ Raspberry Pi 3
○ NoIR Night Vision Camera
● Upgrade Node (was 0.12) & all dependencies
● ES5 to ES6
● More features (Maybe)
○ Cat Identification w/ RFID
○ Photo Booth w/ Filter effects & props
girlie_mac@
More Cat Projects w/ Node.js
girlie_mac@
https://http.cat
Thanks Rogério Vicente for the .cat domain & the API!
Previously: HTTP Status Cats
girlie_mac@
HTTP Status
Cats
Slack Bot
Install it at:
http://girliemac.com/
slack-httpstatuscats/
Tutorial on Medium.com: https://goo.gl/saOUl0
@girlie_mac
Next Project?
● Selfie bot
(à la Mannie the Selfie
Cat)
Mannie the Selfie Cat by
@yoremahm on Instagram
https://www.instagram.com/yoremahm/
girlie_mac@
Danke schön!
@girlie_mac
github.com/girliemac
girlie_mac@
Attribution:
Emoji by Emoji-One (CC-BY 4.0)

More Related Content

PDF
HTML5 - Daha Flash bir web?
PDF
Developing for Mobile
PDF
Augmented Reality in JavaScript
PPT
Advanced Silverlight
PPTX
Beacons, Raspberry Pi & Node.js
PPT
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
PDF
Docker Demo @ IuK Seminar
PDF
I/O Extended 2019 WebTech - New capabilities for the web
HTML5 - Daha Flash bir web?
Developing for Mobile
Augmented Reality in JavaScript
Advanced Silverlight
Beacons, Raspberry Pi & Node.js
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
Docker Demo @ IuK Seminar
I/O Extended 2019 WebTech - New capabilities for the web

What's hot (7)

PDF
Big query - Command line tools and Tips - (MOSG)
PPT
WebGL: GPU acceleration for the open web
PDF
Backend, app e internet das coisas com NodeJS no Google Cloud Platform
PPTX
Eddystone Beacons - Physical Web - Giving a URL to All Objects
PDF
[psuweb] Adaptive Images in Responsive Web Design
PDF
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
PDF
[drupalcampatx] Adaptive Images in Responsive Web Design
Big query - Command line tools and Tips - (MOSG)
WebGL: GPU acceleration for the open web
Backend, app e internet das coisas com NodeJS no Google Cloud Platform
Eddystone Beacons - Physical Web - Giving a URL to All Objects
[psuweb] Adaptive Images in Responsive Web Design
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
[drupalcampatx] Adaptive Images in Responsive Web Design
Ad

Viewers also liked (14)

PDF
Hacking with Nexmo - at EmojiCon Hackathon
PDF
Mathematical Model of Skin Color for Face Detection
PDF
Developer Experience Matters (Short version)
PDF
RaspberryPiPresentation
PDF
Startupfest 2016: JONATHAN BIXBY (Stanley Park Ventures) - How to
PDF
The design secrets behind Slack’s amazing success
PDF
Practical tipsmakemobilefaster oscon2016
PDF
How Autodesk creates better digital experiences with UserTesting
PPTX
Minor on Face Recognition System using Raspberry Pi
PDF
Building Realtime Javascript Apps with PubNub
PDF
Sophia conf 2013 - Le monde du Raspberry
PDF
raspberry pi
PPT
Avihu Efrat's Viola and Jones face detection slides
PDF
Rapport stage IP-MSAN Tunisie télécom
Hacking with Nexmo - at EmojiCon Hackathon
Mathematical Model of Skin Color for Face Detection
Developer Experience Matters (Short version)
RaspberryPiPresentation
Startupfest 2016: JONATHAN BIXBY (Stanley Park Ventures) - How to
The design secrets behind Slack’s amazing success
Practical tipsmakemobilefaster oscon2016
How Autodesk creates better digital experiences with UserTesting
Minor on Face Recognition System using Raspberry Pi
Building Realtime Javascript Apps with PubNub
Sophia conf 2013 - Le monde du Raspberry
raspberry pi
Avihu Efrat's Viola and Jones face detection slides
Rapport stage IP-MSAN Tunisie télécom
Ad

Similar to [JS Kongress 2016] KittyCam.js - Raspberry Pi Camera w/ Cat Facial Detection (20)

PDF
[Longer ver] From Software to Hardware: How Do I Track My Cat with JavaScript
PDF
[HTML5DevConf SF] Hardware Hacking for Javascript Developers
PDF
HTML5: where flash isn't needed anymore
PDF
Is HTML5 Ready? (workshop)
PDF
Is html5-ready-workshop-110727181512-phpapp02
PDF
Python tools to deploy your machine learning models faster
PDF
Moustamera
PDF
Basics cocos2d
PPT
Gdc09 Minigames
KEY
Android workshop
PPT
Naive application development
PDF
Web versus Native: round 1!
PDF
Asynchronous Programming with JavaScript
PDF
The current state of web on mobile - Have smartphone browsers gotten smarter?
PPTX
Don't Over-React - just use Vue!
PPTX
Academy PRO: React native - miscellaneous
PDF
Portable, secure, and lightweight: Wasm runtimes and their use-cases - Natali...
PDF
Augmented reality in web rtc browser
ODP
Non Conventional Android Programming En
[Longer ver] From Software to Hardware: How Do I Track My Cat with JavaScript
[HTML5DevConf SF] Hardware Hacking for Javascript Developers
HTML5: where flash isn't needed anymore
Is HTML5 Ready? (workshop)
Is html5-ready-workshop-110727181512-phpapp02
Python tools to deploy your machine learning models faster
Moustamera
Basics cocos2d
Gdc09 Minigames
Android workshop
Naive application development
Web versus Native: round 1!
Asynchronous Programming with JavaScript
The current state of web on mobile - Have smartphone browsers gotten smarter?
Don't Over-React - just use Vue!
Academy PRO: React native - miscellaneous
Portable, secure, and lightweight: Wasm runtimes and their use-cases - Natali...
Augmented reality in web rtc browser
Non Conventional Android Programming En

More from Tomomi Imura (20)

PDF
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
PDF
[POST.Dev Japan] VS Code で試みる開発体験の向上
PDF
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
PDF
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
PDF
Engineering career is not a single ladder! - Alternative pathway to develope...
PDF
Being a Tech Speaker with Global Mindset
PDF
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
PDF
Slack × Twilio - Uniquely Powering Communication
PDF
[2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
PDF
[2019 south bay meetup] Building more contextual message with Block Kit
PDF
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
PDF
Building a Bot with Slack Platform and IBM Watson
PDF
[日本語] Slack Bot Workshop + Intro Block Kit
PDF
[DevRelCon Tokyo 2019] Developer Experience Matters
PDF
[DevRel Summit 2018] Because we all learn things differently
PDF
[DevRelCon July 2018] Because we all learn things differently
PDF
[Japanese] Developing a bot for your workspace 翻訳ボットを作る!
PDF
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
PDF
Future of the Web with Conversational Interface
PDF
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
[POST.Dev Japan] VS Code で試みる開発体験の向上
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
Engineering career is not a single ladder! - Alternative pathway to develope...
Being a Tech Speaker with Global Mindset
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
Slack × Twilio - Uniquely Powering Communication
[2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
[2019 south bay meetup] Building more contextual message with Block Kit
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
Building a Bot with Slack Platform and IBM Watson
[日本語] Slack Bot Workshop + Intro Block Kit
[DevRelCon Tokyo 2019] Developer Experience Matters
[DevRel Summit 2018] Because we all learn things differently
[DevRelCon July 2018] Because we all learn things differently
[Japanese] Developing a bot for your workspace 翻訳ボットを作る!
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
Future of the Web with Conversational Interface
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...

Recently uploaded (20)

PDF
Smarter Security: How Door Access Control Works with Alarms & CCTV
PPTX
code of ethics.pptxdvhwbssssSAssscasascc
PPTX
Syllabus Computer Six class curriculum s
PPTX
Lecture-3-Computer-programming for BS InfoTech
PDF
Layer23-Switch.com The Cisco Catalyst 9300 Series is Cisco’s flagship stackab...
PPTX
PLC ANALOGUE DONE BY KISMEC KULIM TD 5 .0
PDF
Dynamic Checkweighers and Automatic Weighing Machine Solutions
PPTX
Presentacion compuuuuuuuuuuuuuuuuuuuuuuu
PPTX
了解新西兰毕业证(Wintec毕业证书)怀卡托理工学院毕业证存档可查的
PPTX
quadraticequations-111211090004-phpapp02.pptx
PDF
PPT Determiners.pdf.......................
PPTX
"Fundamentals of Digital Image Processing: A Visual Approach"
PPT
Hypersensitivity Namisha1111111111-WPS.ppt
PPTX
DEATH AUDIT MAY 2025.pptxurjrjejektjtjyjjy
PPTX
Operating System Processes_Scheduler OSS
PPT
Lines and angles cbse class 9 math chemistry
PPTX
Prograce_Present.....ggation_Simple.pptx
PDF
-DIGITAL-INDIA.pdf one of the most prominent
PPTX
5. MEASURE OF INTERIOR AND EXTERIOR- MATATAG CURRICULUM.pptx
PPTX
1.pptxsadafqefeqfeqfeffeqfqeqfeqefqfeqfqeffqe
Smarter Security: How Door Access Control Works with Alarms & CCTV
code of ethics.pptxdvhwbssssSAssscasascc
Syllabus Computer Six class curriculum s
Lecture-3-Computer-programming for BS InfoTech
Layer23-Switch.com The Cisco Catalyst 9300 Series is Cisco’s flagship stackab...
PLC ANALOGUE DONE BY KISMEC KULIM TD 5 .0
Dynamic Checkweighers and Automatic Weighing Machine Solutions
Presentacion compuuuuuuuuuuuuuuuuuuuuuuu
了解新西兰毕业证(Wintec毕业证书)怀卡托理工学院毕业证存档可查的
quadraticequations-111211090004-phpapp02.pptx
PPT Determiners.pdf.......................
"Fundamentals of Digital Image Processing: A Visual Approach"
Hypersensitivity Namisha1111111111-WPS.ppt
DEATH AUDIT MAY 2025.pptxurjrjejektjtjyjjy
Operating System Processes_Scheduler OSS
Lines and angles cbse class 9 math chemistry
Prograce_Present.....ggation_Simple.pptx
-DIGITAL-INDIA.pdf one of the most prominent
5. MEASURE OF INTERIOR AND EXTERIOR- MATATAG CURRICULUM.pptx
1.pptxsadafqefeqfeqfeffeqfqeqfeqefqfeqfqeffqe

[JS Kongress 2016] KittyCam.js - Raspberry Pi Camera w/ Cat Facial Detection