Opencv中XML文件的写入

来源:互联网 发布:c语言两条竖线运算 编辑:程序博客网 时间:2024/05/01 06:32
#include<iostream>#include<vector>#include<opencv2/opencv.hpp>#include<time.h>using namespace std;using namespace cv;int main(){//定义一个类FileStorage fs("test.yaml", FileStorage::WRITE);//开始向文件写入 文件//frameCount是由 用户命名的fs << "frameCount" << 5;time_t rawtime;time(&rawtime);//显示现在的时间fs << "calibrationData" << asctime(localtime(&rawtime));//定义一个矩阵//Mat_<double>(3, 3) 是Mat_ 模版类的构造函数Mat cameraMatrix = (Mat_<double>(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);Mat disCoeffs = (Mat_<double>(5, 1) << 10, 11, 12, 13, 14);//将定义的矩阵写入文件//cameraMatrix是由用户命名fs << "cameraMatrix" << cameraMatrix << "disCoeffs" << disCoeffs;//向文件中写入一个 向量 【数组】//features由用户命名fs << "features" << "[";for (int i = 0; i < 3; i++){int x = rand() % 640;int y = rand() % 480;uchar lbp = rand() % 256;fs << "{:" << "x" << x << "y" << y << "lbp" << "[:";for (int j = 0; j < 8; j++){fs << ((lbp >> j) & 1);}fs << "]" << "}";}fs << "]";fs.release();return 0;}


0 0
原创粉丝点击