Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Ok solved, just use the function "createFileFromUrl" from utils.js. I'll post a detailed answer tomorrow because I signed up today and have to wait... Thank you all for your help!

Ok solved, just use Thanks holger and berak for helping me to solve this problem.
After a deep examination of the code in the example I've found that the xml files are "pre-built" before loading them with the load function. To achieve this it's used
the function "createFileFromUrl" createFileFromUrl from utils.js. I'll post a detailed answer tomorrow because I signed up today and have After that we can finally load our classifier from file.
The final code is as follows (to simplify I've moved the xml file
to wait... Thank you all for your help!the index.html level)

let classifier = new cv.CascadeClassifier();  // initialize classifier

let utils = new Utils('errorMessage'); //use utils class

let faceCascadeFile = 'haarcascade_frontalface_default.xml'; // path to xml

// use createFileFromUrl to "pre-build" the xml
utils.createFileFromUrl(faceCascadeFile, faceCascadeFile, () => {
    classifier.load(faceCascadeFile); // in the callback, load the cascade from file 
});

Make sure to run it in a webserver because it has to do XMLHTTPRequests.

I think an improvement of the documentation (and examples) for the JS version it's needed.