0

I do have a problem with the reading of the objects, stored in the yaml format. As you see (below) I store a std::vector which contain some Limbs which hold a cv::Point, a Probability, Validity and the Id of itself.

person:
   - Nose
   -
      Point: [ 0, 0 ]
      Proba: 0.
      IsValid: 0
      LimbId: 0
   - Neck
   -
      Point: [ 0, 0 ]
      Proba: 0.
      IsValid: 0
      LimbId: 1
person:
...

The store function looks like this and seems to work due to the file output:

    void person::write(cv::FileStorage & fs)
    {
        for (int limbIndex = 0; limbIndex <= 17; limbIndex++) {
            fs << getLimbName(limbIndex) << "{";
            fs << "Point" << getLimb(limbIndex).point;
            fs << "Proba" << getLimb(limbIndex).probability;
            fs << "IsValid" << getLimb(limbIndex).isValid;
            fs << "LimbId" << getLimb(limbIndex).limbId;
            fs << "}";
        }
    }

Unfortunately I m quite unsure how to read the yaml file back, since it contains a list of persons with a list of limbs inside. The best way which I read from it seems to be the FileNodeIterator from : yaml persistence.

So far I would do this :

cv::FileNode personEntries = fileStorage["person"];
cv::FileNodeIterator it = personEntries.begin(), it_end = personEntries.end();
for (; it != it_end; ++it, idx++) {
// should now have one person from the yaml file
}

How do I get the Limbs located in a person also as FileNodeIterator? And how can I read cv::Point from a cv::FileNode?

Thanks for your help!

Daniel Klauser
  • 384
  • 3
  • 16
  • In general I think that you should rather have a `person`s list in some kind of a parent node. Otherwise you can try iterating through the node returned by `FileStorage::getFirstTopLevelNode` or `FileStorage::root`, however I am not sure if this would work, not tested. – michelson Aug 26 '20 at 11:49
  • Maybe take a look here [YAML serialization library](https://stackoverflow.com/questions/244784/yaml-serialization-library-for-c) – Thrasher Aug 26 '20 at 12:07
  • Thanks for your answers, @michelson, the iterator I ll get in the last code snipped is containing the person objects. And Trasher, we would like to keep the codebase small, so no further libraries, it should work with opencv! But thanks for the suggestion. – Daniel Klauser Aug 27 '20 at 05:51

1 Answers1

0

I manage to find a solution, at first, the saving of the person needs to be a List - wr therefore use the "[ person1, person2 ...]" square brackets to surround the objects, there we could then use the FileNoteIterator with:

        cv::FileNodeIterator it = personEntries.begin(), it_end = personEntries.end();
        int idx = 0;
        for (; it != it_end; ++it, idx++) {
            person p;
            p.read(*it);
            persons.push_back(p);
        }

The different membervariables of the person itself can be storead as a map. Therefore we have to take the curved brackets "{ Limb1, Limb2... }". Now every limb has its own Properties which we have to save as Maps too! "{Point : Value ....}" etc.

The second problem was reading the cv::Point object from the file. It seems that it only works with piping.

LimbNode["Point"] >> pt;

Thats it.

Daniel Klauser
  • 384
  • 3
  • 16