使用 openCV 从 xml 文件中读取和显示矩阵
Reading and displaying matrix from xml file with openCV
我正在尝试使用 openCV 从 xml 文件中读取和显示矩阵。XML 文件如下所示:
<?xml version="1.0"?>
<opencv_storage>
<frame_00000>
<pose type_id="opencv-matrix">
<rows>0</rows>
<cols>0</cols>
<dt>u</dt>
<data></data></pose>
<expertCode>3</expertCode>
<autoCode>-1</autoCode></frame_00000>
<frame_00001>
<pose type_id="opencv-matrix">
<rows>0</rows>
<cols>0</cols>
<dt>u</dt>
<data></data></pose>
<expertCode>0</expertCode>
<autoCode>-1</autoCode></frame_00001>
<frame_00002>
<pose type_id="opencv-matrix">
<rows>6</rows>
<cols>1</cols>
<dt>d</dt>
<data>
9.6603986167822176e-02 2.7534827334102827e-02
-7.9839974858475181e-03 2.9772357539313782e+02
2.6446663460538508e+02 1.5645098067258549e+00</data></pose>
<expertCode>0</expertCode>
<autoCode>0</autoCode></frame_00002>
etc...
我已经设法打开了该文件,但是在编译和运行时无法让它打印帧数据。这是我的代码:
#include "opencv2/opencv.hpp"
#include <fstream>
using namespace cv;
using namespace std;
int main()
{
std::cout<< endl << "Reading:" << endl;
FileStorage fs;
fs.open("output.xml", FileStorage::READ);
if (fs.isOpened())
{
cout<<"File is openedn";
}
Mat pose2;
fs["pose"] >> pose2;
std::cout<< pose2;
fs.release();
return (0);
}
问题出在 fs.release() 之前的最后一个代码块上。无论我尝试什么,它都不会显示数据。
我希望它显示 xml 文件中的所有帧数据。我一直在使用OpenCV教程和参考手册作为指南,但它没有帮助。
任何指针将不胜感激,即使它只是我应该使用的命令的基本概述。
FileNode n = fs.root();
for (FileNodeIterator current = n.begin(); current != n.end(); current++) {
FileNode item = *current;
Mat v;
item["pose"] >> v;
cout << v << endl;
}
这行得通! :)
相关文章:
- 从文本文件中读取并输入到数组结构中,然后显示读取的数据C++
- 通过显示一行星号来创建条形图,该条形图将读取数据的输入文件
- 从文本文件中读取数据并删除所有换行符空格,并在 C++ 控制台中显示
- 尝试使用 ifstream 读取数据后显示不正确的数字
- 尝试创建一个读取.txt文件,显示它,计数唯一单词的程序,并在使用了多少次的情况下显示独特的单词.C
- 从TextFile读取数据,并在控制台中显示
- c - 函数选择显示读取后stdin中有数据
- 从文本文件中读取行并显示在屏幕上
- 如何从文件中读取并将内容存储在动态 2D 数组中并以网格格式显示
- 使用 getline 函数读取文件,但第一列显示为空
- 无法使用 fstream 从二进制文件中读取字符串,而是显示奇怪的符号
- 通过列读取文本文件,并显示列值的所有数组
- 如果语句内部循环不读取完全正确的代表显示错误
- 从文本文件读取到显示到多个联系人
- 从文本文件中读取尺寸和表格内容后显示表格
- 读取 TGA 显示空值而不是颜色数据
- 使用 openCV 从 xml 文件中读取和显示矩阵
- 读取 C++ 中的文本文件不显示任何输出
- 显示异常,以读取TXT文件
- 从文件中读取HTML标签并在终端中正确显示它们