zoukankan      html  css  js  c++  java
  • C++数据文件存储与加载(利用opencv)

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

    #include <opencv2/opencv.hpp>
    #include <iostream>
    #include <string>
    using namespace cv;
    using namespace std;
    1
    2
    3
    4
    5
    存储
    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;
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    加载
    //加载数据,类似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;
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    完整代码
    #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;
    }

    ---------------------

  • 相关阅读:
    设计模式的分类
    SQL Server 2005 TSQL 学习笔记:排名函数
    JS正则表达式语法
    魅族 “拜产品教”公司的优秀与局限
    jqueryMobile初始化组件
    Loading Scripts Without Blocking
    LabJs学习笔记:分析图
    翻转的css3样式
    IE(IE6/IE7/IE8)支持HTML5标签
    我的空间轨迹!
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11075595.html
Copyright © 2011-2022 走看看