Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

opencv.js building WASM cv.face.createFacemarkLBF()

When using the detectMultiScale function, it throws a binding error.

I understand that OpenCV.js loads and fires the onload event before it's really initialized. To wait until OpenCV.js is really ready, we have to do: cv['onRuntimeInitialized']=()=>{ // do all your work here };

I understand that files need to be created in memory and OpenCV.js has an non-advertised utility class called Utils that can be used for exactly that and other useful operations.

So I did the following; cv['onRuntimeInitialized']=()=>{ // do all your work here let utils = new Utils('errorMessage'); let faceCascadeFile = 'haarcascade_frontalface_alt2.xml'; let faceCascade = new cv.CascadeClassifier(); let src = cv.imread('imageSrc'); let gray = new cv.Mat(); cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY, 0); let faces = new cv.RectVector(); let msize = new cv.Size(0, 0); console.log("face CascadeClassifier"); utils.createFileFromUrl(faceCascadeFile, faceCascadeFile, () => { faceCascade.load(faceCascadeFile); faceCascade.detectMultiScale(gray, faces, 1.1, 3, 0, msize, msize);

            let facemark = new cv.face.createFacemarkLBF();
            console.log('yes cascade ready to load.');

        });
    };

I get the following error: Uncaught TypeError: Cannot read property 'createFacemarkLBF' of undefined

Is there any work around solution to solve this?

Thanks in advance!

opencv.js building WASM cv.face.createFacemarkLBF()

When using the detectMultiScale function, it throws a binding error.

I understand that OpenCV.js loads and fires the onload event before it's really initialized. To wait until OpenCV.js is really ready, we have to do: cv['onRuntimeInitialized']=()=>{ // do all your work here };

I understand that files need to be created in memory and OpenCV.js has an non-advertised utility class called Utils that can be used for exactly that and other useful operations.

So I did the following; following;

    cv['onRuntimeInitialized']=()=>{
         // do all your work here
         let utils = new Utils('errorMessage');
         let faceCascadeFile = 'haarcascade_frontalface_alt2.xml';
         let faceCascade = new cv.CascadeClassifier();
         let src = cv.imread('imageSrc');
         let gray = new cv.Mat();
         cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY, 0);
         let faces = new cv.RectVector();
         let msize = new cv.Size(0, 0);
         console.log("face CascadeClassifier");
         utils.createFileFromUrl(faceCascadeFile, faceCascadeFile, () => {
             faceCascade.load(faceCascadeFile);
             faceCascade.detectMultiScale(gray, faces, 1.1, 3, 0, msize, msize);

msize);

            let facemark = new cv.face.createFacemarkLBF();
            console.log('yes cascade ready to load.');

        });
    };

I get the following error: Uncaught TypeError: Cannot read property 'createFacemarkLBF' of undefined

Is there any work around solution to solve this?

Thanks in advance!