-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
49 lines (28 loc) · 992 Bytes
/
test.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
var config = require('./lib/config');
var FaceRec = require('./lib/facerec').FaceRec;
var hfr = new FaceRec(config);
// constant
var threshold = 20;
var prevX;
var prevY;
setInterval(function() {
var result = hfr.detect();
console.log('result:' + JSON.stringify(result));
if (result && result.pos_x && result.pos_y) {
var newX = result.pos_x;
var newY = result.pos_y;
var deltaX = newX - prevX;
var deltaY = newY - prevY;
if (Math.abs(deltaX) > threshold) {
var direction = deltaX > 0 ? "right" : "left";
console.log("moving head to " + direction + " , distance" + Math.abs(deltaX));
}
if (Math.abs(deltaY) > threshold) {
var direction = deltaY > 0 ? "down" : "up";
console.log("moving head to " + direction + " , distance" + Math.abs(deltaY));
}
console.log('updating x and y');
prevX = newX;
prevY = newY;
}
}, 5000);