终端输出:
writing images
image1.jpg myfi.png baboon.jpg
writing mats
R = [1, 0, 0;
0, 1, 0;
0, 0, 1]
T = [0;
0;
0]
writing MyData struct
{ id = mydata1234, X = 3.14159, A = 97}
reading images
image1.jpg
myfi.png
baboon.jpg
reading R and T
R = [1, 0, 0;
0, 1, 0;
0, 0, 1]
T = [0;
0;
0]
read mdata
{ id = mydata1234, X = 3.14159, A = 97}
attempting to read mdata_b
read mdata_b
{ id = , X = 0, A = 0}
Try opening input.yml to see the serialized data.
Read data from string
attempting to read mdata_b from string
read mdata
{ id = mydata1234, X = 3.14159, A = 97}
Write data to string
writing MyData struct
{ id = mydata1234, X = 3.14159, A = 97}
Created string:
%YAML:1.0
---
mdata:
A: 97
X: 3.1415926535897931e+00
id: mydata1234
```cpp
/*
* 文件存储示例 filestorage_sample 演示了 OpenCV 序列化功能的用法
*/
#include "opencv2/core.hpp" // 包含核心 OpenCV 库文件
#include <iostream> // 包含标准输入输出流库
#include <string> // 包含字符串相关库
// 使用命名空间中的元素,避免每次都需要 std::前缀
using std::string;
using std::cout;
using std::endl;
using std::cerr;
using std::ostream;
using namespace cv; // 使用 OpenCV 命名空间
// 帮助函数,说明程序如何使用
stati