我一直在努力一段時間無法使用FileStorage打開文件:它是來自以下代碼的一部分:\ opencv \ sources \ samples \ cpp \ tutorial_code \ calib3d \ camera_calibration \ camera_calibration.cpp:Opencv FileStorage操作 - 無法打開:
FileStorage fs(inputSettingsFile, FileStorage::READ); // Read the settings
if (!fs.isOpened())
{
cout << "Could not open the configuration file: \"" << inputSettingsFile << "\"" << endl;
return -1;
}
它總是失敗。也嘗試過絕對路徑,仍然失敗。環境:Opencv版本:2.4.8,Windows 7(32位)和Visual Studio 2010.(其實,嘗試2.4.2和VS2008,同樣的問題)我缺少什麼?
要驗證權限,請在FileStorage之前添加常規cpp文件。正常的cpp文件讀取工作正常:
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;
}
你有權限讀取文件嗎? –
文件路徑的擴展是什麼? – 0x499602D2
文件路徑爲「」.xml「」,「」.yml「」還是「.yaml」「?請選擇您的文章上的編輯按鈕並回復我們。我認爲你還沒有足夠的聲望來評論。 – 0x499602D2