File: face-detection-rectangle.js

package info (click to toggle)
node-opencv 6.0.0%2Bgit20180416.cfc96ba0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 24,632 kB
  • sloc: xml: 476,707; cpp: 5,950; makefile: 114; sh: 59; ansic: 20
file content (22 lines) | stat: -rwxr-xr-x 664 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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++) {
      var 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');
  });

});