opencv中Mat类对象创建的方法总结

#include
#include

using namespace std;
using namespace cv;
//如何创建Mat对象!
int main(int argc,char**argv[])
{
	Mat src;
	src = imread("F:\\LX(OpenCV)\\ny1.bmp");
	if (src.empty())
	{
		//cout<<"could not load image\n"<(0);

	printf("第一个像素值:%d\n", *out);

	int row = src.rows;
	int col = src.cols;
	int c = src.channels();
	int d = dst.channels();
	printf("src的行:%d\n",row);
	printf("src的列:%d\n",col);
	printf("src的通道数:%d\n",c);
	printf("dst的通道数:%d\n", d);

	Mat M(3, 3, CV_8UC3, Scalar(0, 255, 0));
	cout << "M=" << endl << M << endl;

	Mat N;
	N = Mat(3,3, CV_8UC3, Scalar(0, 254, 0));
	
	cout << "N=" << endl << N << endl;

	Mat a;
	a.create(3, 3, CV_8UC3 );
	a = Scalar(23, 145, 224);

	Mat r(a);//只是复制头和指针,不复制数据
	cout << "r=" << endl << r << endl;


	cout << "a=" << endl << a << endl;

	Mat b = Mat::eye(3,3, CV_8UC3); //Mat b = Mat::zeros(3,3, CV_8UC3);
	cout << "b=" << endl << b << endl;

	//定义小数组
	Mat kernel=(Mat_(3,3)<<0,-1,0,-1,5,-1,0,-1,0);
	cout << "kernel=" << endl << kernel << endl;


	namedWindow("dst");
	imshow("dst", dst);

	waitKey(0);
	return 0;
}

 

你可能感兴趣的:(图像处理,OpenCV,OpenCV的,图像处理)