#include<opencv2/opencv.hpp>
#include<iostream>
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"<<endl;endl=end line,即输出一行换一行
printf("could not load image\n");
return -1;
}
namedWindow("src");
imshow("src", src);
/*Mat dst;
dst = Mat(src.size(), src.type());
dst = Scalar(134, 123, 33);
*/
/*Mat dst;
src.copyTo(dst);
*/
Mat dst;
//dst = src.clone();
cvtColor(src, dst, COLOR_BGR2GRAY);
const uchar*out = dst.ptr<uchar>(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_<int>(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;
}