-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcameraRecognition.js
46 lines (41 loc) · 1.21 KB
/
cameraRecognition.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
let watson = require(
'watson-developer-cloud'
);
// execute OS linux command
let exec = require('child_process').exec;
// linux command to capture picture from camera
let takePic = "raspistill -w 300 -h 300 -t 2 -o sample.jpg";
/* the visual analysis api in watson limits uploaded picture size less than 2M
* execute this command to compress picture to 1500Kb
*/
let fs = require('fs');
let visual_recognition = watson.visual_recognition({
api_key: 'b6c9eaec4f1a331526564bf555c7031298ace7ae',
version: 'v3',
version_date: '2016-05-20'
});
/* take a picture and compress it finally recognize
*/
function analysis(callback) {
exec(takePic, function(err, stdout, stderr) {
if (err) {
console.log('error:' + stderr);
} else {
console.log("jpg ready!");
visual_recognition.classify({
"images_file": fs.createReadStream(
"sample.jpg"),
"threshold": 0.0
}, function(err, res) {
if (err) {
console.log(err);
} else {
callback(res);
}
});
}
});
};
module.exports = {
analysis: analysis
};