Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

there is a nice js face detection / recognition sample here , please take a look, i'd propose, you use the pretrained openface dnn model for recognition, like this:

// once, on startup:
function loadModel(callback) {
  var utils = new Utils('');
  var recognModel = 'https://raw.githubusercontent.com/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7';
      utils.createFileFromUrl('face_recognition.t7', recognModel, () => {
        document.getElementById('status').innerHTML = '';
        netDet = cv.readNetFromCaffe('face_detector.prototxt', 'face_detector.caffemodel');
        netRecogn = cv.readNetFromTorch('face_recognition.t7');
        callback();
      });
    });
  });
};

// for each (cropped face) image:
//! [Get 128 floating points feature vector]
function face2vec(face) {
  var blob = cv.blobFromImage(face, 1.0 / 255, {width: 96, height: 96}, [0, 0, 0, 0], true, false)
  netRecogn.setInput(blob);
  var vec = netRecogn.forward();
  blob.delete();
  return vec;
};

then compare distance between feature vectors using cv.norm(), cosine distance or even a simple dot product (smaller==better)

(please also check out the dnn based face detection used in the sample, it's much faster and more rubust than the cascades you're using now !)