我正在使用OpenCV编写带有嵌套列表的yaml文件。输出看起来很奇怪,但也许是正确的
void nested_yaml() {
cv::FileStorage write_fs;
write_fs.open("../trajectory.yml", cv::FileStorage::WRITE);
for ( unsigned i = 1; i < 3 ; i++ ) {
char temp_str_fs[20];
sprintf(temp_str_fs, "i_%03d", i);
write_fs << temp_str_fs << "[";
for (ushort j = 0; j < 4; j++) {
char temp_str_fc[20];
sprintf(temp_str_fc, "j_%03d", j);
write_fs << temp_str_fc << "[";
write_fs << "{:" << "name" << "hello" << "x" << 1 << "y" << 2 << "}";
write_fs << "]";
}
write_fs << "]";
}
write_fs.release();
}
第一个问题是输出是否正确?
第二个问题是如何使用cv :: FileNode回读j_00x下的元素。
yaml文件的输出
%YAML:1.0
---
i_001:
- j_000
-
- { name:hello, x:1, y:2 }
- j_001
-
- { name:hello, x:1, y:2 }
- j_002
-
- { name:hello, x:1, y:2 }
- j_003
-
- { name:hello, x:1, y:2 }
i_002:
- j_000
-
- { name:hello, x:1, y:2 }
- j_001
-
- { name:hello, x:1, y:2 }
- j_002
-
- { name:hello, x:1, y:2 }
- j_003
-
- { name:hello, x:1, y:2 }