-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor-detector-tester.js
65 lines (51 loc) · 1.36 KB
/
color-detector-tester.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// The bounds start at 109 115 which is blue
//
// to change the bounds enter the lower bounds followed by a space then the
// upper bounds
//
console.log('To change bounds enter the lower bounds then the upper bounds and press enter');
console.log('[lower bounds] [upper bounds] [enter]');
var bounds = {
'blue': [109, 115],
}
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var cd = require('./lib/rockathon/color-detector');
cd = new cd(13, 28);
cd.setMinArea(8000);
if (bounds[process.argv[2]]) {
cd.setBounds.apply(cd, bounds[process.argv[2]]);
}
var cv = require('opencv');
var camera = new cv.VideoCapture(0);
var win = new cv.NamedWindow('Display Window', '400x400');
rl.on('line', function (input) {
cd.setBounds.apply(cd, input.split(' '));
console.log('bounds set to', input.split(' '))
});
var sound = {
process: function(L, R) {
for (var i = 0; i < L.length; i++) {
L[i] = R[i] = Math.random() * 0.25;
}
}
};
var main = function() {
camera.read(function(err, im) {
var objs = cd.detect(im);
for (var i = objs.length - 1; i >= 0; i--) {
var obj = objs[i];
im.ellipse(obj[0], obj[1], 5, 5, [0, 255, 0], 2);
};
im = im.flip(1);
win.show(im);
setTimeout(main, 20);
});
};
main();
process.on('exit', function(code) {
});