Global persistence.cpp:505 open Can't open file in read mode

[ERROR:0@3.179] global persistence.cpp:505 open Can’t open file: ‘haarcascade_frontalface_default.xml’ in read mode
put_char @ opencv.js:30
opencv.js:30 [ERROR:0@3.184] global persistence.cpp:505 open Can’t open file: ‘haarcascade_eye.xml’ in read mode

Any clue why im getting these errors? The files are there

let faceCascade = new cv.CascadeClassifier()
let eyeCascade = new cv.CascadeClassifier()

// load pre-trained classifiers
faceCascade.load('haarcascade_frontalface_default.xml')
eyeCascade.load('haarcascade_eye.xml')
1 Like

still looks like a ‘file not found’ problem to me
(check file path)

its same directory as script. Used full path too, same error

as berak it seems a file not found or file already opened error :

            file = fopen(filename.c_str(), !write_mode ? "rt" : !append ? "wt" : "a+t");
            if (!file)
            {
                CV_LOG_ERROR(NULL, "Can't open file: '" << filename << "' in " << (!write_mode ? "read" : !append ? "write" : "append") << " mode");
                return false;
            }
````Preformatted text`

im using the opencv tutorial for eye detection of that helps OpenCV: Face Detection using Haar Cascades

please learn what a “current working directory” is.

dont understand what im supposed to do. both files are literally there and as said i used both relative and full paths. im on windows

“same directory as script” means nothing. relative paths aren’t resolved relative to the source file, nor the directory containing the executable, but the Current Working Directory.

if you used an absolute path, you should show us this path. perhaps it’s broken.

and you really must test the validity of the path and the existence of the file like so:

File f = new File(filePathString);
if(f.exists()) { 
    // that would be sensible to check
}

On windows when you copy file name using mouse sometime there is an first character hidden

ok i tried to check if the file exists with full path and i get

Not allowed to load local resource:

I guess this means its a chrome problem? I tried everything, allow-read-files flag, another server extention, clear dns etc nothing

EDIT: not a chrome problem i get this in edge

Not allowed to load local resource: file:///C:/Users/User/Desktop/dist/haarcascade_frontalface_default.xml

Also note that im not using backend. I want the file load to happen on the browser

That’s not an opencv problem. Check stackoverflow with error message

i swear this thing is retarded. i setup a node server so i dont need to access the users disk and i still get the error.

I have never heard of that nor experienced it. please explain what this is.

I completely missed that you’re dealing with OpenCV.js. sorry for giving you java code for testing the existence of a file.

you need to know where your code runs. does it run in the browser, or in the node server?

do you run this in any virtualization?

all those kinds of things. you need to check them, and you need to be aware of the amount of abstraction/complication you have.

no prob but i still have no idea what the problem is. I thought it was the fact that browser cant access client files so i put them in a server but error remains

So the server has the xml files and also serves the html. Then the html uses the xml files from the server but i get the same error

your code does not run in the node server. it runs in the browser.

decide where you want it to run. do you want the user’s browser to execute the program, or do you want your server to execute it?

I’m sure there are ways to get access to the haar cascade file from inside the browser. that was the original intention of OpenCV.js

check yourself. Run nodemon index.js

Got it through virustotal (c576aad2419723733692be22fe97800c0903c8b612ec36891a4fa3ff31a98d90) just to be sure

https://www.google.com/search?client=firefox-b-d&q=windows+u%2B202A

a “LEFT-TO-RIGHT EMBEDDING”… might happen to people with RTL languages set in their UI. it never happens to many people, and it probably happens a lot to some people. I am inclined to doubt that this is the case here.

apparently im not the only one with this prob Face Detection using Haar Cascades in opencv.js - Node.js error