-
Notifications
You must be signed in to change notification settings - Fork 1
/
FaceStream.js
executable file
·32 lines (25 loc) · 962 Bytes
/
FaceStream.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
var jsfeat = require('jsfeat');
var stream = require('stream');
jsfeat.bbf.face_cascade = require('./bbf_face.js');
var h = 135;
var w = 240;
FaceStream.prototype = Object.create(stream.Transform.prototype, {
constructor: { value: FaceStream}
});
function FaceStream() {
stream.Transform.call(this, {objectMode: true});
this.gray_img = new jsfeat.matrix_t(w, h, jsfeat.U8_t | jsfeat.C1_t);
jsfeat.bbf.prepare_cascade(jsfeat.bbf.face_cascade);
}
FaceStream.prototype.faceDetection = function (rgbaImage) {
var gray_img = this.gray_img;
jsfeat.imgproc.grayscale(rgbaImage, gray_img.data);
var pyr = jsfeat.bbf.build_pyramid(gray_img, 24*2, 24*2, 4);
var rects = jsfeat.bbf.detect(pyr, jsfeat.bbf.face_cascade);
return jsfeat.bbf.group_rectangles(rects, 1);
}
FaceStream.prototype._transform = function(rgbaImage, encoding, done) {
this.push(this.faceDetection(rgbaImage));
done();
};
module.exports = FaceStream;