opencv4nodejs: Facemark example not running

Hi !

When I tried to launch the example “facemark”, I get the following error :

facemark.setFaceDetector(frame => {
         ^

TypeError: facemark.setFaceDetector is not a function
    at Object.<anonymous> (/home/loophole/EventBots/vision/opencv4nodejs/examples/facemark.js:27:10)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:201:16)
    at bootstrap_node.js:626:3

When I comment this line, I get another one :

const faces = facemark.getFaces(gray);
                       ^

TypeError: facemark.getFaces is not a function
    at Object.<anonymous> (/home/loophole/EventBots/vision/opencv4nodejs/examples/facemark.js:35:24)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:201:16)
    at bootstrap_node.js:626:3

Am I missing something ?

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 18 (2 by maintainers)

Most upvoted comments

Okay I actually managed to get the example working. I didn’t realize I could be using the face classifier directly. I have the following code if it can help someone :

const cv = require("../");
const fs = require("fs");
const path = require("path");

if (!cv.xmodules.face) {
  throw new Error("exiting: opencv4nodejs compiled without face module");
}

const facemarkModelPath = "../data/face/";
const modelFile = path.resolve(facemarkModelPath, "lbfmodel.yaml");

if (!fs.existsSync(modelFile)) {
  console.log("could not find landmarks model");
  console.log(
    "download the model from: https://raw.githubusercontent.com/kurnianggoro/GSOC2017/master/data/lbfmodel.yaml"
  );
  throw new Error("exiting: could not find landmarks model");
}

const classifier = new cv.CascadeClassifier(cv.HAAR_FRONTALFACE_ALT2);

// create the facemark object with the landmarks model
const facemark = new cv.FacemarkLBF();
facemark.loadModel(modelFile);

const image = cv.imread("../data/got.jpg");
const gray = image.bgrToGray();

var faceClassifierOpts = {
    minSize: new cv.Size(30, 30),
    scaleFactor: 1.126,
    minNeighbors: 1,
}

const faces = classifier.detectMultiScale(gray, faceClassifierOpts).objects
// use the detected faces to detect the landmarks
const faceLandmarks = facemark.fit(gray, faces);

for (let i = 0; i < faceLandmarks.length; i++) {
  const landmarks = faceLandmarks[i];
  for (let x = 0; x < landmarks.length; x++) {
    image.drawCircle(landmarks[x], 1, new cv.Vec(0, 255, 0), 1, cv.LINE_8);
  }
}

cv.imshowWait("VideoCapture", image);