-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (43 loc) · 1017 Bytes
/
index.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
43
44
45
46
47
48
49
50
51
const NodeWebcam = require("node-webcam");
const QrCode = require("qrcode-reader");
const Jimp = require("jimp");
// Webcam options
const opts = {
width: 1280,
height: 720,
quality: 100,
delay: 0,
saveShots: true,
output: "jpeg",
device: false,
callbackReturn: "location",
verbose: false,
};
// Create the webcam instance
const Webcam = NodeWebcam.create(opts);
function captureAndDecode() {
Webcam.capture("test_picture", function (err, data) {
if (err) {
console.log(err);
return;
}
Jimp.read("test_picture.jpg", function (err, image) {
if (err) {
console.log(err);
return;
}
let qr = new QrCode();
qr.callback = function (err, value) {
if (err) {
console.log(err);
return;
}
console.log(value.result);
console.log("------------------------");
};
qr.decode(image.bitmap);
});
});
}
// Continually capture and decode
setInterval(captureAndDecode, 5000);