I’ve got a cross platform error with OpenCV 2.3.1 and 2.4 on both VS2010 and Xcode 4.2
If I use cv::imread while giving the path to the image as an absolute path, it works. It does not work if that is a relative path. I usually put the images in the same dir as the code as well as all other dirs in the project just to be careful.
Much appreciated if anyone can answer this. Thank you!
Harish.
In Visual Studio, when you create a C++ project, it sets the project’s working directory to the project dir, not the output dir of the executable.
That means that if you run the project from inside Visual Studio (by using the F5 button or the “Start Debugging” button), the program that you are writing won’t be able to see the files that are in the same dir as the .exe file. But when you run the program from Windows Explorer (by double-clicking it) it will work as expected.
To fix this, you need to go in the Project properties window under
Configuration properties->Debugging, and change the Working Directory from$(ProjectDir)to$(OutputPath). You should change this both for the Debug and the Release configuration.I don’t know if this is the same case in XCode, but you can try this solution there too.