Opencv,读取 XML 相机校准文件时出错
Opencv, error while reading XML file for camera calibration
我正在使用 opencv 提供的 the code 进行相机校准。
我编辑了设置文件以包含我自己的目录,它看起来像这样:
<?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" -> path/image,但引发了以下异常:
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 文件不正确)
您的文件末尾似乎缺少 </opencv_storage>
。您需要关闭标签才能使 XML 有效。
好的,问题解决了:
对于第二个问题
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 文件中插入图像,如我的问题所示。
我遇到了同样的问题,只需删除目录路径中的空格就可以了
C:/Users/user/Documents/Visual Studio 2013/Projects/calebration/x.xml
应该是:
C:/Users/user/Documents/Visual_Studio_2013/Projects/calebration/x.xml
我正在使用 opencv 提供的 the code 进行相机校准。 我编辑了设置文件以包含我自己的目录,它看起来像这样:
<?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" -> path/image,但引发了以下异常:
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 文件不正确)
您的文件末尾似乎缺少 </opencv_storage>
。您需要关闭标签才能使 XML 有效。
好的,问题解决了: 对于第二个问题
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 文件中插入图像,如我的问题所示。
我遇到了同样的问题,只需删除目录路径中的空格就可以了
C:/Users/user/Documents/Visual Studio 2013/Projects/calebration/x.xml
应该是: C:/Users/user/Documents/Visual_Studio_2013/Projects/calebration/x.xml