1. 程式人生 > >opencv Mat 矩陣基本操作

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";