繁体   English   中英

使用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 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;
    } 

这有效! :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM