Ask Your Question
0

Problem loading haar cascade file in opencv.js

asked 2018-04-20 00:38:41 -0600

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 .

edit retag flag offensive close merge delete

Comments

detectMultiScale throws an error when we build with WASM. Is there any similar workaround?

kavikode gravatar imagekavikode ( 2019-08-20 20:14:06 -0600 )edit
1

@kavikode , please do not post answers here, if you have a question or a comment, thank you.

berak gravatar imageberak ( 2019-08-21 02:59:57 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-05-28 15:56:23 -0600

3r1c gravatar image

Assuming you also loaded util.js, "create" the .xml file before loading it:

let utils = new Utils('errorMessage');
let faceCascadeFile = 'haarcascade_frontalface_default.xml';
utils.createFileFromUrl(faceCascadeFile, faceCascadeFile, () => {
    console.log('cascade ready to load.');
});
edit flag offensive delete link more

Comments

I've signed up to thank you !

Khazad gravatar imageKhazad ( 2018-07-06 06:56:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-04-20 00:38:41 -0600

Seen: 2,810 times

Last updated: Aug 20 '19