-
Notifications
You must be signed in to change notification settings - Fork 0
/
FaceProcessing.js
43 lines (35 loc) · 1.13 KB
/
FaceProcessing.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
const _ = require('underscore');
class FaceProcessing {
constructor() {
this.face = [];
this.mouth = [];
this.nose = [];
this.eyeLeft = [];
this.eyeRight = [];
}
processFaceFeatures(features) {
_.each(features, (feature, name) => {
this[name] = feature;
// Check if eye is detected
if (!this.eyeRight.length && this.eyeLeft.length) {
// Let's assume that if right eye is not detected,
// it has same property as left eye
this.eyeRight = this.eyeLeft;
}
if (!this.eyeLeft.length && this.eyeRight.length) {
// Let's assume that if left eye is not detected,
// it has same property as right eye
this.eyeLeft = this.eyeRight;
}
});
}
calculateGlassesWidth() {
const leftEyeX = this.eyeLeft[0].getX();
const rightEyeX = this.eyeRight[0].getX();
const rightEyeWidth = this.eyeRight[0].getWidth();
// Get length from left eye X to right eye X (the most left position of the right eye)
const totalLeftEyeWidth = rightEyeX - leftEyeX;
return totalLeftEyeWidth + rightEyeWidth;
}
}
module.exports = FaceProcessing;