OpenCV.js unable to load haar cascades [closed]
Hi everyone,
I was tring to implement the face detection example with opencv.js.
The problem is that there's no way of importing the necessary haar cascade.
My project structure is as follows:
- index.html
- js
- myjs.js
- opencv.js
- utils.js
- haar
- haarcascade_frontalface_default.xml
In "myjs.js" I try to load the cascade as shown in the example using my path to the cascade:
let classifier = new cv.CascadeClassifier();
classifier.load('../haar/haarcascade_frontalface_default.xml');
The function returns always false indicating the loading failure, independently if using the relative or the absolute path. Because of this I can't use the "detectMultiScale" function...
Can anyone help me please?
Hmm i think this is related on how the resource is resolved via javascript. Can you add a breakpoint in the js file and look where things go wrong?
How is the resource loaded - via ajax(if so - the webserver muss allow access to that file) ? I hope the js is not minified - otherwise you would need to get the "sources".
the cascades are loaded via ajax, and some webbrowsers don't allow to do ajax "from disk".
try to start a local webserver, and download your index.html from there.
also, iirc, the location is relative to the index, so
haar/haarcascade_frontalface_default.xml