1、使用Mat()构造函数
定义一个二维多通道图像
Mat M(2, 2, CV_8UC3, Scalar(0, 0, 255));
cout << "M = " << endl << " " << M << endl;
/*
*2行2列
* CV_8UC3 :使用8为unsigned char型,每个像素由3个元素组成
* Scalar:short类型向量: 使用指定的定制化来初始化矩阵
*/
2、IpIImage* 转换为Mat对象
IplImage *img = cvLoadImage("F:\\MyCode\\dcq.jpg", 1);
Mat mtx = cvarrToMat(img, true); //转换IplImage * --->Mat
3、用 Mat类的Create成员函数
Mat M;
M.create(4, 4, CV_8UC(3));
cout << "M = " << endl << " " << M << endl;
注意:此函数不能为矩阵设置初值,只是在改变尺寸时重新为矩阵数据开辟内存而已
4、用Matlab式的初始化方式
Mat M = Mat::eye(4, 4, CV_64F);
cout << "M = " << endl << " " << M << endl;
Mat Z = Mat::zeros(3, 3, CV_64F);
cout << "Z = " << endl << " " << Z << endl;
Mat F = Mat::ones(2, 2, CV_64F);
cout << "F = " << endl << " " << F << endl;
5、
Mat M = (Mat_(3, 3) << 0, 1, 2, 1, 2, 3, 2, 3, 4) ;
cout << "M = " << endl << " " << M << endl;
6、为一个已经存在的Mat对象创建一个新的信息头
Mat M = (Mat_(3, 3) << 0, 1, 2, 1, 2, 3, 2, 3, 4) ;
cout << "M = " << endl << " " << M << endl << endl << endl;
Mat RowClone = M.row(1).clone();
cout << "RowClone=" << endl << " " <
--