【opencv】示例-filestorage.cpp 使用 FileStorage 类进行序列化与反序列化的示例

b570c9ea88f8716ec03f6f1f24dfb462.png

终端输出:

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值