-
Notifications
You must be signed in to change notification settings - Fork 6
/
webcam.js
45 lines (37 loc) · 916 Bytes
/
webcam.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// See node-webcam docs for additional instructions.
// https://www.npmjs.com/package/node-webcam
const NodeWebcam = require( 'node-webcam' );
const Thing = require('Grow.js');
const fs = require('fs');
const opts = {
width: 1280,
height: 720,
delay: 0,
quality: 100,
output: 'jpeg',
verbose: true
}
const cam = new Thing({
properties: {
name: 'Camera',
interval: 100000
},
picture: function () {
NodeWebcam.capture( 'image', opts, ( err, data )=> {
if ( !err ) console.log( 'Image created!' );
fs.readFile('./' + data, (err, data) => {
if (err) throw err; // Fail if the file can't be read.
this.sendImage(data);
});
});
},
start: function () {
let interval = this.get('interval');
this.interval = setInterval(()=> {
this.picture();
}, interval);
},
stop: function () {
clearInterval(this.interval);
}
});