博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++数据文件存储与加载(利用opencv)
阅读量:4450 次
发布时间:2019-06-07

本文共 1432 字,大约阅读时间需要 4 分钟。

首先请先确认已经安装好了opencv3及以上版本。

#include <opencv2/opencv.hpp>

#include <iostream>
#include <string>
using namespace cv;
using namespace std;
存储
then

int main()

{
//创造一些要存的数据先
string words = "hello, my guys!";
float n = 3.1415926;
Mat m = Mat::eye(3, 3, CV_32F);
//开始创建存储器
FileStorage save("data.yml", FileStorage::WRITE);// 你也可以使用xml格式
save << "words" << words;
save << "number" << n;
save << "matrix" << m;
save.release();
//存储完毕
cout << "finish storing" << endl;
加载
//加载数据,类似Python字典的用法,创建加载器
FileStorage load("data.yml", FileStorage::READ);
float nn;
Mat mm;
string ww;
load["words"] >> ww;
load["number"] >> nn;
load["matrix"] >> mm;
cout<< ww << endl << nn << endl << mm;
cout << endl << "That's the end";
load.release();
return 0;
}
完整代码
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>

using namespace cv;

using namespace std;

int main()

{
string words = "hello, my guys!";
float n = 3.1415926;
Mat m = Mat::eye(3, 3, CV_32F);
FileStorage save("data.yml", FileStorage::WRITE);
save << "words" << words;
save << "number" << n;
save << "matrix" << m;
save.release();
cout << "finish storing" << endl;

FileStorage load("data.yml", FileStorage::READ);

float nn;

Mat mm;
string ww;
load["words"] >> ww;
load["number"] >> nn;
load["matrix"] >> mm;
cout<< ww << endl << nn << endl << mm;
cout << endl << "That's the end";
load.release(http://www.my516.com);

return 0;

}

转载于:https://www.cnblogs.com/ly570/p/11069908.html

你可能感兴趣的文章
scala的4中for循环,及while和do while循环
查看>>
Go语言程序结构
查看>>
自定义圆形头像
查看>>
JavaScript&jQuery.动态创建元素
查看>>
WebBrowser记录
查看>>
什么是FreeMaker
查看>>
设计模式学习笔记(总结篇:模式分类)
查看>>
算法笔记_075:蓝桥杯练习 最短路(Java)
查看>>
TCP的三次握手/建立连接
查看>>
Python 教程阅读笔记(一):使用解释器
查看>>
运算符重载
查看>>
SDWebImage 新版接口使用方法
查看>>
简单的jQuery检测注册用户名
查看>>
DataTable导出为word,excel,html,csv,pdf,.txt
查看>>
android ListView详解
查看>>
软件工程 第一次作业
查看>>
Content Server HA搭建
查看>>
vue-textarea 自适应高度
查看>>
(2)数据结构——线性表(链表)实现
查看>>
[leetCode]Linked List Cycle I+II
查看>>