开发者

opencv serialization with nested sequence

开发者 https://www.devze.com 2023-03-30 16:58 出处:网络
I have the following situation: typedef struct { int value; string color; } PositionElement; struct { int row;

I have the following situation:

typedef struct {
    int value;
    string color;
} PositionElement;

struct {
   int row;
   int column;
   vector<PositionElement&开发者_运维知识库gt; positionElements;  // has 120 values
}     PositionInformation;

How can I use opencv serialization on this? The samples/tutorials/documentation don't have an example of squences nested inside structs.

I start having trouble when attempting to implement this function:

void PositionInformation::read(const FileNode &node);

I can't figure out how to iterate through the positionElements to populate them.


I was hoping to add the serialization functions directly into those structs, like is suggested in the documentation: adding read()/write() functions to the structs and global read()/write() too with FileNodes and the new datatypes as inputs. I thought that would be slick so that I could then have my higher level app just serialize/deserialize the PositionInformation struct.

However since I'm the only one who is going to use those structs, I decided to just follow the examples of writing data to XML/YAML on the C++ cheatsheet, which do not add serialization to individual structs, but do read/write collections containing sequences, and that worked fine. What I was trying to do was overkill anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消