1,
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
//创建一个2*2 类型为32位的浮点型三通道的矩阵
//前面两个参数是创建矩阵的行和列
//第三个参数是创建矩阵的类型
//第四个参数是填充矩阵的数值
Mat img(2, 2, CV_32FC3, Scalar(0, 255, 255));
cout << "矩阵元素" << endl << img << endl;
return 0;
}
2、
//采用Matlab的方式初始化
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat array1 = Mat::eye(4, 4, CV_64F);
Mat array2 = Mat::ones(4, 4, CV_32F);
Mat array3 = Mat::zeros(4, 4, CV_8UC1);
cout << "对角矩阵" << endl << array1 << endl;
cout << "满1矩阵" << endl << array2 << endl;
cout << "全0矩阵" << endl << array3 << endl;
return 0;
}
3、
int main()
{
Mat array = (Mat_<double>(3, 3) << 0, -1, 5, -1, 5, -1, 0, -1, 0);
cout << "array=" << endl << array << endl;
return 0;
}
4、
int main()
{
//创建一个3*3的3通道矩阵
Mat srcImage(3, 3, CV_8UC3, Scalar(0, 0, 255));
Mat copyImage;
srcImage.copyTo(copyImage);
//输出第一行结果
Mat newImage = srcImage.row(0).clone();
cout << "运行结果" << endl << newImage << endl;
return 0;
}