#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(void)
{
/*最常用的方法是直接使用Mat()构造函数,这种方法简单明了:对于二维多通道
图像,首先要定义其尺寸,即行数与列数。然后需要定义存储元素的数据类型以及
每个矩阵点的通道数*/
Mat A(3, 3, CV_8UC3, Scalar::all(0));
cout << "A=" << endl << " " << A << endl << endl;
/*在c++中通过构造函数进行初始化*/
/*int sz[3] = { 2,2,2 };
Mat B(3, sz, CV_8UC3, Scalar::all(0));
cout << "B=" << endl << " " << B<< endl << endl;*/
/*在已存在的IplImage指针创建信息头:*/
/*iplImage* img = cvLoadImage("1.jpg", 1);
Mat mtx(img);*/
/*利用Create()函数*/
Mat C;
C.create(2, 2, CV_8UC2);
cout << "C=" << endl << " " << C << endl << endl;
/*采用Matlab形式初始化方式:zeros(),ones(),eyes()*/
Mat E = Mat::eye(4, 4, CV_64F);
cout << "E=" << endl << " " << E<< endl << endl;
Mat O = Mat::ones(2, 2, CV_32F);
cout << "O=" << endl << " " << O << endl << endl;
Mat Z= Mat::zeros(2, 2, CV_32F);
cout << "Z=" << endl << " " << Z << endl << endl;
/*对小矩阵使用逗号分隔式初始化函数*/
Mat D = (Mat_<double>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
cout << "C=" << endl << " " << D<< endl << endl;
/*使用成员函数clone()或copyTo(),为已存在Mat对象创建新的信息头。*/
Mat RowClone = C.row(1).clone();
cout << "RowClone=" << endl << " " << RowClone << endl << endl;
return 0;
}
Mat对象的不同创建方式
最新推荐文章于 2024-06-10 21:42:16 发布