mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
23 lines
678 B
JavaScript
Executable File
23 lines
678 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.x + face.width, face.y + face.height], COLOR, 2);
|
|
}
|
|
|
|
im.save('./tmp/face-detection-rectangle.png');
|
|
console.log('Image saved to ./tmp/face-detection-rectangle.png');
|
|
});
|
|
|
|
});
|