'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)