创建OpenCV中的`Mat`对象可以通过以下几种方法:
1. 使用`Mat()`构造函数:
```cpp
Mat M(2, 2, CV_8UC3, Scalar(0, 0, 255)); // 创建一个2x2的3通道图像,初始值为蓝色
```
2. 使用`create()`函数:
```cpp
Mat M;
M.create(4, 4, CV_8UC2); // 创建一个4x4的2通道图像,不指定初始值
```
3. 使用Matlab风格的函数,如`zeros()`, `ones()`等:
```cpp
Mat M = Mat::zeros(2, 2, CV_8UC3); // 创建一个2x2的全0的3通道图像
```
4. 为已存在的`IplImage`指针创建`Mat`对象:
```cpp
IplImage *img = ...; // 假设已有IplImage对象
Mat mtx(img); // 将IplImage对象转换为Mat对象
```
5. 使用`clone()`或`copyTo`为一个已存在的`Mat`对象创建一个新的信息头:
```cpp
Mat C(3, 3, CV_8UC3, Scalar(1, 2, 3));
Mat Rowclone = C.row(1).clone(); // 克隆第二行
```
请根据您的具体需求选择合适的方法来创建`Mat`对象。