1、创建方式
> 1. Mat ()
> 2. Mat (int rows, int cols, int type)
> 3. Mat (Size size, int type)
> 4. Mat (int rows, int cols, int type, const Scalar &s)
> 5. Mat (Size size, int type, const Scalar &s)
> 6. Mat (int ndims, const int *sizes, int type)
> 7. Mat (int ndims, const int *sizes, int type, const Scalar &s)
传参演示:(example是创建的图片的Mat对象)
> 1、outexample= Mat(example.rows, example.cols,> example.type());//创建了一个和原图片的大小一致,类型一致的图片对象
> 2、outexample=> Mat(example.size(),example.type());//传入图片的size和type outexample => Scalar(125, 0, 255);//创建图片填充的颜色
> 3、outexample= Mat(example.rows,> example.cols, example.type() ,Scalar(125, 0, 255));
> 4、outexample=Mat(example.size(),example.type(),Scalar(125, 0, 255));
> 5、outexample=Mat(500,500, example.type());
> 6、Mat(int ndims, const int* sizes, int type, const Scalar & s);
2、常用的命令
部分复制:般情况下只会复制Mat对象的头和指针部分,不会复制数据部分
> Mat B(A)
完全复制:如果想把Mat对象的头部和数据部分一起复制
>方式一:
> Mat G = A.clone();
> 方式二:
> Mat G;
> A.copyTo(G);
3、创建数组
方式一:rows参数传入行,cols参数传入列,第三个CV_8UC3中的8表示每个通道占8位、U表示无符号、C表示Char类型、3表示通道数目是。第四个参数Scalar是向量表示初始化每个像素值是多少,向量长度对应通道数目一致
> Mat outexample;
> outexample.create(rows, cols, CV_8UC3);
> outexample => Scalar(127, 127);
方式二:定义数组
> Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
> cout << "C = " << endl << " " << C << endl << endl;