opencv3学习笔记——XML或YAML文件的写入

本程序适合vs2017,其他版本需要修改头文件。

Mat类矩阵初始化:1、直接初始化。2、利用数组初始化。

1、    Mat cameraMatrix = (Mat_(3, 3) << 1000, 0, 320, 0, 1000, 240, 0, 0, 1);//矩阵直接初始化

2、    double a[5][1] = { 1.0,0.01,-0.001,0,0 };//矩阵通过数组进行初始化
    Mat distCoeffs = Mat(5, 1, CV_64F,a);

cout中空格可用 cout<<"a"<

printf的用法:printf("a=%d,b=%d/n",a,b);

#include "pch.h"
#include "iostream"
#include "opencv2/opencv.hpp"
#include "time.h"
using namespace cv;
using namespace std;
int main()
{
	FileStorage fs("test.yaml", FileStorage::WRITE);
	//开始文件写入
	fs << "frameCount" << 5;
	time_t rawtime; time(&rawtime);
	Mat cameraMatrix = (Mat_(3, 3) << 1000, 0, 320, 0, 1000, 240, 0, 0, 1);//矩阵直接初始化
	double a[5][1] = { 1.0,0.01,-0.001,0,0 };//矩阵通过数组进行初始化
	Mat distCoeffs = Mat(5, 1, CV_64F, a);
	fs << "cameraMatrix" << cameraMatrix << "distCoeffs" << distCoeffs;
	fs << "feature" << "[";
	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();
	printf("文件读写完毕,请在工程目录下查看生成的文件");
	getchar();
	return 0;
}

 

你可能感兴趣的:(opencv3学习笔记)