Last active
February 5, 2017 06:47
-
-
Save tnoborio/f5c91a7c6dc5626854d154dd4796b6af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const NodeWebcam = require( "node-webcam" ), | |
vision = require('google-cloud').vision, | |
notifier = require('node-notifier') | |
const visionClient = vision({ | |
projectId: process.env.GCLOUD_PROJECT, | |
keyFilename: './keyfile.json' | |
}) | |
const cam = NodeWebcam.create({ | |
width: 1280, | |
height: 720, | |
delay: 0, | |
quality: 100, | |
output: "jpeg", | |
verbose: true | |
}) | |
const notify = (message) => { | |
notifier.notify({ | |
title: "表情検知", | |
message: message | |
}) | |
} | |
const detect = (path) => { | |
visionClient.detectFaces(path, function(err, faces) { | |
console.log("detect result") | |
if (err) { | |
console.log(err) | |
} else if (faces && faces.length > 0) { | |
const face = faces[0] | |
console.log(face) | |
if (face.sorrow) { | |
notify('😣悲しみの表情を検知しました。') | |
} else if (face.anger) { | |
notify('😠怒りの表情を検知しました。') | |
} else if (face.joy) { | |
notify('😁喜びの表情を検知しました。') | |
} | |
} | |
}) | |
} | |
setInterval(() => { | |
const path = `/tmp/face_picture.jpg` | |
cam.capture(path, (err) => { | |
if (err) { | |
console.log( err ) | |
} else { | |
detect(path) | |
} | |
}) | |
}, 3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "face", | |
"version": "1.0.0", | |
"description": "", | |
"main": "main.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"google-cloud": "^0.46.1", | |
"node-cloud-vision-api": "^0.2.0", | |
"node-notifier": "^5.0.2", | |
"node-webcam": "^0.3.4" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment