opencv Mat 矩阵基本操作

下面介绍Mat矩阵的基本操作:

1、可以使用Mat::eye,Mat::ones,Mat::zeros 对矩阵进行初始化;

2、矩阵可以进行加减乘除操作;

	Mat m = Mat::eye(5, 5, CV_32F);
	Mat n = Mat::ones(5, 5, CV_32F);
	Mat p = Mat::zeros(5, 5, CV_32F);
	Mat m1 = Mat::eye(5, 5, CV_8UC1);
	cout << " \n=======m=======\n";
	cout << m;
	cout << " \n=======n=======\n";
	cout << n;
	cout << " \n=======p=======\n";
	cout << p;
	cout << " \n=======m1=======\n";
	cout << m1;

	cout << " \n=====n + m======\n";
	Mat madd = m + n;
	cout << madd;

	cout << " \n=====n - m=====\n";
	Mat msub = n - m;
	cout << msub;

	cout << " \n=====n*m=====\n";
	Mat mmul = n*m;
	cout << mmul;

	cout << " \n=====标量矩阵=====\n";
	cout << m * 2;

	cout << " \n=====矩阵元素乘法=====\n";
	cout << "(madd+2) *(madd+3)=\n" << (madd + 2).mul(madd + 3);

	cout << " \n===============\n";
opencv Mat 矩阵基本操作_第1张图片

你可能感兴趣的:(opencv)