mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Fixed #274 by changing the x2,y2 second array when drawing the rectangle to width,height (see Matrix.cc)
23 lines
660 B
JavaScript
Executable File
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');
|
|
});
|
|
|
|
});
|