What is Mat Class
The basic Image Container, an n-dimensional dense numerical single-channel or multi-channel array.
1. Costructor
You can create Mat object by different ways.
Warining
When you create mat object by using Size or Point class, yout have to reverse rows and columns.
2. Set Elements
When you create Mat object without data, the elements is set to '0' by defaults. If you want to change elements, you can use setTo, Mat::ones, Mat::zeros, Mat::eye method.
Or can use arrays
if you want to change specific elements, change specific elements in arrays.
3. Mat_ Class
Mat_ class inherited the Mat Class.
4. Matx Class (Simple Mat)
Matx class is useful to create simple mat object.
The basic Image Container, an n-dimensional dense numerical single-channel or multi-channel array.
1. Costructor
You can create Mat object by different ways.
Mat mat(3, 3, CV_32F); Mat mat2(10, 2, CV_64FC2); // 2x10 64 bit float 2 channelMat img(Size(5, 3), CV_32FC3); // 5x3 32bit float 3 channelMat mat3(2, 3, CV_8U, Scalar(255)); // 3x2 8bit unsign_int, all elements set 255
Warining
When you create mat object by using Size or Point class, yout have to reverse rows and columns.
2. Set Elements
When you create Mat object without data, the elements is set to '0' by defaults. If you want to change elements, you can use setTo, Mat::ones, Mat::zeros, Mat::eye method.
Mat mat(3, 3, CV_32F); mat.setTo(10); // all elements set to 10
Mat mat7 = Mat::ones(3, 5, CV_32F); // all elements set to '1'Mat mat8 = Mat::zeros(2, 3, CV_32F); // all elements set to '0'Mat mat9 = Mat::eye(3, 3, CV_32F); // make Unit matrix
Or can use arrays
float data[] = { 1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f}; Mat mat4(2, 3, CV_32F, data); // declare and set elements by using arrays
if you want to change specific elements, change specific elements in arrays.
Mat mat4(2, 3, CV_32F, data); data[0] = 2.7f; cout << mat4 << endl; // (0,0) is changed 1.1f -> 2.7f
3. Mat_ Class
Mat_ class inherited the Mat Class.
Mat_ <int> mat10(2, 4); Mat_ <int> mat11(3, 3, 10); mat10 << 1,2,3,4,5,6,7,8; // set elements in mat10 object
4. Matx Class (Simple Mat)
Matx class is useful to create simple mat object.
Matx<int, 3,3> m1(1,2,3,4,5,6,7,8,9); Matx<int, 3,2> m2(1,2,3); // not setting default elements set to '0'
Comments
Post a Comment