2017-07-20 215 views
0

我正在使用opencv提供的the code進行相機校準。 我已經編輯的設置文件,包含我自己的目錄,它看起來像這樣:Opencv,讀取XML文件進行相機校準時出錯

<?xml version="1.0"?> 
<opencv_storage> 
<images> 
"20170720_024951.jpg" 
"20170720_025001.jpg" 
"20170720_025014.jpg" 
"20170720_025023.jpg" 
"20170720_025034.jpg" 
"20170720_025048.jpg" 
"20170720_025103.jpg" 
"20170720_025115.jpg" 
"20170720_025124.jpg" 
"20170720_025133.jpg" 
"20170720_025147.jpg" 
"20170720_025155.jpg" 
"20170720_025211.jpg" 
</images> 

我提供完整的圖像路徑,但得到這個錯誤:

Invalid input detected. Application stopping.

這裏是部分代碼在其中,我發現了錯誤:

Settings s; 
const string inputSettingsFile = "C:/Users/user/Documents/Visual Studio 2013/Projects/calibration/x.xml"; 
FileStorage fs(inputSettingsFile, FileStorage::READ); // Read the settings 
if (!fs.isOpened()) 
{ 
    cout << "Could not open the configuration file: \"" << inputSettingsFile << "\"" << endl; 
    return -1; 
} 
fs["Settings"] >> s; 
fs.release();           // close Settings file 
//! [file_read] 

//FileStorage fout("settings.yml", FileStorage::WRITE); // write config as YAML 
//fout << "Settings" << s; 

if (!s.goodInput) 
{ 
    cout << "Invalid input detected. Application stopping. " << endl; 
    return -1; 
} 

由oencv提供的原始文件在屬性(圖像的路徑)周圍不包含「」,所以我試圖首先將圖像的路徑插入XML文件而不使用使用雙引號「path/image .JPG」 - >路徑/圖像,但下列異常發生:

OpenCV Error: Parsing error (C:/Users/user/Documents/Visual Studio 2013/Projects/calebration/x.xml(1): Attribute value should be put into single or double quotes) in icvXMLParseTag, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\persistence.cpp, line 2157

,加入後‘’被人所建議的,異常消失,但仍停留在第一個錯誤(這是在告訴我假設 xml文件的格式不正確)

+0

你試過使用反斜槓\而不是斜槓/ ??不知道這是在XML的情況下,但你可能需要轉義反斜槓 – api55

+0

非常感謝你,我已經嘗試了\和/但還有其他問題,解決了我的答案在下面! –

回答

0

好的問題解決了: 對於第二個問題

OpenCV Error: Parsing error (C:/Users/user/Documents/Visual Studio 2013/Projects/calebration/x.xml(1): Attribute value should be put into single or double quotes) in icvXMLParseTag, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\persistence.cpp, line 2157

事實證明,我的圖片的路徑包含空格,所以乾脆是由圖像移動到不包含空格另一個目錄解決。

第一個問題我完全是個傻瓜! 使用你需要兩個xml文件的代碼!
第一個是你把校準的設置(例如,你是使用國際象棋棋盤,圓形網格,或其他什麼,以及你使用的電路板的大小,以及目錄到第二個XML你的地方圖像存在,....)
在第二個xml文件中插入圖像,如我的問題所示。

0

看起來好像缺少了</opencv_storage>在文件末尾。您需要關閉標籤以使XML有效。

+0

非常感謝! 我錯過了,但也有其他問題。 –