目录
1、什么是Mat类
2、Mat类组成
3、Mat类能存储的数据类型
4.Mat类的创建
4.1 利用矩阵宽、高和类型参数创建
4.2 利用矩阵Size()结构和数据类型参数来创建
4.3 利用已有Mat类来创建
5、Mat类的赋值
5.1 创建时赋值
5.2 类方法赋值
5.3 枚举赋值
6、Mat类数据的读取
6.1 Mat类的常用属性
6.2 at方法读取矩阵元素
6.3 矩阵元素地址定位方式访问元素
7.Mat支持的运算
7.1 符号运算
7.2 两个矩阵相乘
7.3 OpenCV中提供的运算函数
Mat类是OpenCV中用于存储矩阵数据的类型。
Tp:用户可自定义类型
Mat a(3, 3, CV_8S);
Mat a(Size(3,3), CV_8SC(2));//C(2)通道数为2
Mat f(Size(3,3),CV_8U,Scalar(0,55,255));
a=Mat::eye(3,3,CV_8U);
Mat a = (Mat_(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);
Mat c0(5,5,CV_8UC1,Scalar(4,5,6));
Mat c1(5,5,CV_8UC2,Scalar(4,5,6));
Mat c2(5,5,CV_8UC3,Scalar(4,5,6));
cout << a.at(0, 0) << endl;
Vec2b vc = c1.at(0,1);
cout << vc << endl;
cout << (int)vc[0] << endl;
cout << (double)(*(c2.data + c2.step[0] * 3 + c2.step[1] * 3 + 3))<< endl;
cout << vc[0] << endl;
Mat a = (Mat_(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);
Mat b = (Mat_(3, 3) << 1, 2, 3, 7, 8, 9, 4, 5, 6);
Mat c = (Mat_(3, 3) << 1.0, 2.1, 3.2, 4.3, 5.4, 6.5, 7.6, 8.7, 9.8);
Mat d = (Mat_(3, 3) << 1.0, 2.1, 3.2, 4.3, 5.4, 6.5, 7.6, 8.7, 9.8);
cout << "两个矩阵的和=" << endl << a + b << endl;
cout << "两个矩阵的差=" << endl << c - d << endl;
cout << "矩阵数乘=" << endl << 2 * a << endl;
cout << "矩阵数除 = " << endl << d / 2.0 << endl;
cout << "矩阵减数 = " << endl << a - 1 << endl;
cout << "两矩阵相乘=" << endl << c*d << endl;
cout << "矩阵内积 = " << endl << a.dot(b) << endl;
cout << "矩阵对应位相乘=" << endl << a.mul(b) << endl;
cout << "两个矩阵最小值=" << endl << min(a, b) << endl;