Mat 构造方法实例

来源:互联网 发布:电脑版解压软件 编辑:程序博客网 时间:2024/06/08 11:09
  • Mat M(2,2,CV_8UC3,Scalar(0,0,255));
    cout << "M= "<< endl << "  "<< M << endl;
M :   [0,0,255 0,0,255
 0,0,255, 0,0,255 ]
sizeof(M) = 56####
CV_8UC3:
CV_[位数][是否为带符号类型U为Unsigned][类型前缀]C[通道数]
Scalar 是short向量
使用定制化值来初始化矩阵
还可以用来表示颜色
  • 多维矩阵
int sz[]={3,3,3};
Mat L(3,sz,CV_8UC,Scalar::all(0));
——这里编译不能通过??
  • IpIImage 指针创建信息头
Ip1Image* img = cvLoadImage("1.jpg",1);
Mat mtx(img);
  • 利用Create() 函数
Mat M;
M.create(4,4,CV_8UC(2));
cout << M << endl;
—— 输出4行,205 205 205 205 205 205 205 205
——为什么是 205?
  • Matlab式初始化方式
Mat M= Mat::eye(4,4,CV_64F);
cout << M << endl;
//单位矩阵
cout << sizeof(M);
     //还是56 果然是信息头,不包含矩阵


Mat M= Mat::ones(4,4,CV_64F);
cout << M << endl;
// 全为1 矩阵
cout << sizeof(M);
      //56

Mat M= Mat::zeros(4,4,CV_64F);
cout << M << endl;
cout << sizeof(M);
  //56  全为0

  • 使用逗号,对小矩阵分隔式  分别 赋值
Mat M= (Mat_<double>(3,3)<< 0,-1,2,3,4,5,67,8,0);
cout << M << endl;
cout << sizeof(M);
  • 通过已经存在的对象创建信息头
Mat M= (Mat_<double>(3,3)<< 0,-1,2,3,4,5,67,8,0);
cout << M << endl;
cout << sizeof(M);


cout << """""""""""""""" << endl;
Mat Rowclone = M.row(1).clone();
cout << Rowclone << endl;
原创粉丝点击