使用openCV从xml文件读取和显示矩阵 [英] Reading and displaying matrix from xml file with openCV

查看:238
本文介绍了使用openCV从xml文件读取和显示矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用openCV从xml文件中读取和显示一个矩阵。 XML文件如下所示:

I'm trying to read and display a matrix from within an xml file, using openCV. The XML file looks like this:

  <?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...

我已经设法打开文件,让它在编译和运行时打印帧数据。这是我有的代码:

I have managed to open the file, but I can't get it to print the frame data when it is compiled and run. This is the code I have:

#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()之前的最后一个代码块。无论我尝试什么,它都不显示数据。

The problem is with the last block of code before fs.release(). No matter what I try, it doesn't display the data.

我想让它显示xml文件中的所有帧数据。我已经使用OpenCV教程和参考手册作为指南,但它只是没有帮助。

I want it to display all the frame data from the xml file. I've been using the OpenCV tutorials and reference manual as a guide, but it's just not helping.

任何指针都会赞赏,即使它只是一个基本的轮廓。

Any pointers would be appreciated, even if it's just a basic outline of the commands I should be using.

推荐答案

 FileNode n = fs.root();
    for (FileNodeIterator current = n.begin(); current != n.end(); current++) {
        FileNode item = *current;
        Mat v;
        item["pose"] >> v;
        cout << v << endl;
    } 

:)

这篇关于使用openCV从xml文件读取和显示矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆