opencv java 显示mat_OpenCV3之显式创建Mat对象的7种方法

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类型向量: 使用指定的定制化来初始化矩阵

*/

2a5119ea3aa711461afac6f32e5712ea.png

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;

opencv java 显示mat_OpenCV3之显式创建Mat对象的7种方法_第1张图片

注意:此函数不能为矩阵设置初值,只是在改变尺寸时重新为矩阵数据开辟内存而已

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;

opencv java 显示mat_OpenCV3之显式创建Mat对象的7种方法_第2张图片

5、

Mat M = (Mat_(3, 3) << 0, 1, 2, 1, 2, 3, 2, 3, 4) ;

cout << "M = " << endl << " " << M << endl;

0c6a4503f70e5a46c8f28961a6914b4c.png

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

opencv java 显示mat_OpenCV3之显式创建Mat对象的7种方法_第3张图片

--

你可能感兴趣的:(opencv,java,显示mat)