2017-07-20 51 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

非常感谢! 我错过了,但也有其他问题。 –