node-opencv/examples/face-detection-rectangle.js
Max Ehrlich d79f633547 Fix mistake in face detection example
Fixed #274 by changing the x2,y2 second array when drawing the rectangle to width,height (see Matrix.cc)
2015-07-31 11:25:28 -04:00

23 lines
660 B
JavaScript
Executable File

var cv = require('../lib/opencv');
var COLOR = [0, 255, 0]; // default red
var thickness = 2; // default 1
cv.readImage('./files/mona.png', function(err, im) {
if (err) throw err;
if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size');
im.detectObject('../data/haarcascade_frontalface_alt2.xml', {}, function(err, faces) {
if (err) throw err;
for (var i = 0; i < faces.length; i++) {
face = faces[i];
im.rectangle([face.x, face.y], [face.width, face.height], COLOR, 2);
}
im.save('./tmp/face-detection-rectangle.png');
console.log('Image saved to ./tmp/face-detection-rectangle.png');
});
});