OpenCV学习笔记之创建Mat图像

 

今天总结了5种创建Mat图像的方法,都是可以直接运行的。

 

代码:

#include
#include
using namespace cv;
using namespace std;

int main() {
	/*
	CV_8UC1 8位1通道
	CV_8UC3 8位3通道
	CV_32FC1 32位1通道
	CV_64FC1 64位1通道
	*/

	//创建Mat图像(像素值自定义)
	Mat MM(5, 5, CV_8UC1, Scalar(128,0,0));// 参数(int rows, int cols, int type, const Scalar& s)
	cout << "MM = " << endl << " " << MM << endl;

	//创建Mat图像(像素值205)
	Mat MC;
	MC.create(5, 5, CV_8UC1);
	cout << "MC = "<< endl << " "  << MC << endl;

	//创建Mat图像(像素值单位矩阵)
	Mat E = Mat::eye(5, 5, CV_8UC1);
	cout << "E = " << endl << " " << E << endl;

	//创建Mat图像(像素值全1矩阵)
	Mat O = Mat::ones(5, 5, CV_32FC1);
	cout << "O = " << endl << " " << O << endl;

	//创建Mat图像(像素值全0矩阵)
	Mat Z = Mat::zeros(5, 5, CV_64FC1);
	cout << "Z = " << endl << " " << Z << endl;
	
	waitKey();
	system("pause");
	return 0;
}

结果:

OpenCV学习笔记之创建Mat图像_第1张图片

你可能感兴趣的:(Opencv)