c++ - 使用 openCV 从 xml 文件读取和显示矩阵

标签 c++ xml 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 opened\n";
    }


    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++ - 使用 openCV 从 xml 文件读取和显示矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13832782/

相关文章:

c++ - 错误 : assigning to 'char' from incompatible type 'const char *'

c++ - 将具有任意参数和占位符的函数存储在类中并稍后调用

python - 从维基百科转储中提取平行文本

java - JAXB 通过映射

c++ - 当我尝试访问 CvMat 数据结构成员的第一个元素时,为什么会得到这个 ^@

c++ - 编译器是否假定 "this"在 Debug模式下不是 nullptr?

java - 解析 XSL 时 Saxon 中的 NullPointerException

c# - 高斯模糊C#实现(类似OpenCV)

c++ - 在 OpenCV 中是否有关于级联分类器的更详细引用?

c++ - <ctime> 的替代品