Reputation: 51
I have been struggling for a while by the failure to open file using FileStorage: It is part of the code from: \opencv\sources\samples\cpp\tutorial_code\calib3d\camera_calibration\camera_calibration.cpp:
FileStorage fs(inputSettingsFile, FileStorage::READ); // Read the settings
if (!fs.isOpened())
{
cout << "Could not open the configuration file: \"" << inputSettingsFile << "\"" << endl;
return -1;
}
It always failed. Tried absolute path also, still fails. Environment: Opencv version: 2.4.8, windows 7 (32-bit) and Visual Studio 2010. (Actually, tried 2.4.2 and VS2008, same problem) Anything I am missing?
To verify permission, added regular cpp file read before FileStorage. the regular cpp file read works fine:
int main()
{
////Use two ways to open and read the file "in_VID5.xml"
string inputSettingsFile = "in_VID5.xml";
//// Method 1: cpp read file - ok
ifstream myfile(inputSettingsFile);
string line;
if(myfile.is_open())
{
while (getline(myfile, line))
{
////It does come here
cout << line <<'\n';
}
myfile.close();
}
Sleep(1000);
////Method 2: opencv read file - fails
FileStorage fs(inputSettingsFile, FileStorage::READ); // Read the settings
if (!fs.isOpened())
{
////It fails
cout << "Could not open the configuration file: \"" << inputSettingsFile << "\"" << endl;
return -1;
}
return 0;
}
Upvotes: 4
Views: 4940
Reputation: 11
I had the same problem until I realized that the constructor doesn't work with the READ flag. So what I do is: - I use the constructor with the falg APPEND. If I use WRITE the contents of the file is deleted. - Then I open with the READ flag and work with the content.
Upvotes: 1
Reputation: 45
Maybe the compile mode you used with the wrong library.
If your compile mode is debug, the OpenCV library must be debug version and only debug version, not include release version.
So try to check the compile profile .
Upvotes: 0
Reputation: 23
Actually I have encountered with the same problem. After some checking I realized that the constructor of cv::FileStorage always return a bad pointer (Bad Ptr). Actually the same problem happens to other opencv library functions such as imread in the existing project.
I just solved the bug by revising the symbol file cache settings with checking the option:
Options -> Debugging -> Symbols -> Microsoft Symbol Servers
Maybe someone can give a clear explanation to the weird problem with this symptom and cure.
Upvotes: 0