c++ Mat对象的创建方式和常用命令

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());
> 6Mat(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;
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值