简体   繁体   中英

Do-while statement in OpenCV C++ with xml

I am trying to read data from an xml file using OpenCV. The data is from a video recording.

What I want to do is write a "do-while" statement that basically says "Do nothing while there is no data from that frame"

I tried using FileNode::empty() in the while statement, but I don't think I'm understanding the syntax properly, because I keep getting the error "Call to non-static member function without an object argument"

I'm a complete novice to programming, so I really have no idea how I should be structuring the statement correctly. I've been going through the tutorials and the reference manual for OpenCV, but it's not clearing anything up for me.

Below is an except from the very beginning of the xml file:

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

Basically, what I want it to do is look at each of the frame nodes, determine whether there's any data in them, and ignore them if there isn't.

Any tips on the syntax of the FileNode::empty() statement would be appreciated.

EDIT:

Here is the code I have so far, based off the tutorials for opening the XML file

#include "opencv2/opencv.hpp"
#include <fstream>

using namespace cv;

int main()
{
    FileStorage fs("output.xml", FileStorage::READ);
    do {
        ;
    } while ();
}

The opencv XML API is very simple, really just to get a cv::Mat on/off disk. If you are trying to do more than this I would use a regular XML library.

But most XML parsers aren't designed to read a file that is changing dynamically, they normally open the file and build a tree structure.

Could you just keep trying to open the file, check if it has changed, close it, wait and then re-open ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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