我使用 OpenCV FileStorage 将地图存储在 yaml 文件中,如下所示:
cv::FileStorage fs("file.yaml.gz", cv::FileStorage::WRITE);
std::string somekey = ...;
double someval = ...;
fs << "mymap" << "{:" << somekey << someval << "}";
现在,我想取回数据,但我不知道地图的键。我猜代码应该是这样的:
cv::FileStorage fs("file.yaml.gz", cv::FileStorage::READ);
cv::FileNode fn = fs["mymap"];
// fn has type == cv::FileNode::MAP
// fn has size == 1 element (one pair)
// fn[0] returns also a MAP with 1 element
是否有可能在没有密钥的情况下获得该地图的所有对?我已经检查了cv::FileNodeIterator
,但它似乎并没有解决这个问题。C 接口CvFileNode
允许在提供键之后检索值。