Ask Your Question

Revision history [back]

Problem loading haar cascade file in opencv.js

i am to implement face detection using opencv.js but haar cascade file is not getting loaded.

 let faceCascade = new cv.CascadeClassifier();
console.log(faceCascade);
if(faceCascade.load('haarcascade_frontalface_default.xml'))
{
}else{
console.log("cascade not loaded");
}
let cap = new cv.VideoCapture(video);
 const FPS = 30;
 function processVideo() {
let begin = Date.now();
cap.read(src);
cv.cvtColor(src, dst, cv.COLOR_RGBA2GRAY);
console.log(faceCascade);
faceCascade.detectMultiScale(gray, faces, 1.1, 3, 0, msize, msize);
for (let i = 0; i < faces.size(); ++i)
 {
   let roiGray = gray.roi(faces.get(i));
   let roiSrc = src.roi(faces.get(i));
   let point1 = new cv.Point(faces.get(i).x, faces.get(i).y);
   let point2 = new cv.Point(faces.get(i).x + faces.get(i).width,
                             faces.get(i).y + faces.get(i).height);
   cv.rectangle(src, point1, point2, [255, 0, 0, 255]);
   roiGray.delete(); roiSrc.delete();
 }
    cv.imshow("canvas", dst);
     let delay = 1000/FPS - (Date.now() - begin);
    setTimeout(processVideo, delay);
 }

my haar cascade file is in the same folder .