-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathface_detection.js
More file actions
28 lines (26 loc) · 1.2 KB
/
Copy pathface_detection.js
File metadata and controls
28 lines (26 loc) · 1.2 KB
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
"use strict";
var args = require('./commargs.js')(),
fs = require('fs'),
F = require('./filterwithcanvas.js'),
parallel = !!args.options['parallel'],
haarcascade_frontalface_alt = require('./haarcascade_frontalface_alt.js'),
face_detector = F.CompositeFilter([
F.ColorMatrixFilter().grayscale(),
//F.HistogramEqualizeFilter(F.MODE.GRAY),
F.HaarDetectorFilter(haarcascade_frontalface_alt, 1, 1.2, 0.25, 1, false, 0.2)
]).update(false);
console.log('Detection runs "' + (parallel ? 'parallel' : 'synchronous') + '"');
if (parallel) face_detector.worker(true);
console.log('Loading..');
fs.readFile(__dirname+'/che.jpg', function(err, buffer) {
if (err) console.log('error while reading image: ' + err.toString());
else F.Image.load(buffer, function(img) {
console.log('Detecting..');
face_detector.apply(img, function() {
if (parallel) face_detector.worker(false);
var features = face_detector.filter(1).metaData().objects;
console.log(features.length + (1 === features.length ? ' feature was found' : ' features were found'));
if (features.length) console.log(JSON.stringify(features));
});
});
});