C ++ data file storage and loading (use OpenCV)

First, make sure been installed opencv3 and above.

#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
存储
then

main int ()
{
// create some data to be stored
String = words "Hello, My Guys!";
a float n-= 3.1415926;
Mat Mat :: m = Eye (. 3,. 3, CV_32F);
// start creating memory
FileStorage save ( "data.yml", FileStorage :: WRITE); // you can also use the xml format of
the Save << "words" << words;
the Save << "Number The" << the n-;
the Save << "the Matrix" < <m;
save.release ();
// been stored
cout << "finish storing" << endl ;
loading
// load data, similar Python dictionary usage, creating loader
FileStorage load ( "data.yml", FileStorage : : the READ);

a 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;
}

Guess you like

Origin www.cnblogs.com/ly570/p/11069908.html