#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
using namespace cv;
using namespace std;
int main()
{
Mat src;
//原图
src = imread(".//pic//test.jpg",IMREAD_UNCHANGED);
if (src.empty())
{
cout << "can not load image" << endl;
return -1;
}
namedWindow("input", CV_WINDOW_AUTOSIZE);
imshow("input", src);
//创建Mat
//Mat dst;
//dst = Mat(src.size(), src.type());
////RGB三通道赋值
//dst = Scalar(0, 0, 0);
//namedWindow("output", CV_WINDOW_AUTOSIZE);
//imshow("output", dst);
//copy的使用
Mat dst;
//src.copyTo(dst);
//色彩空间的转换
cvtColor(src, dst, CV_BGR2GRAY);
namedWindow("output", CV_WINDOW_AUTOSIZE);
imshow("output", dst);
printf("输入图像的通道数:%d\n", src.channels());
printf("输出图像的通道数:%d\n", dst.channels());
//输出某一个点的像素
int cols = dst.cols;
int rows = dst.rows;
printf("rows:%d cols:%d\n", cols, rows);
const uchar* firstRow = dst.ptr<uchar>(0);
printf("first pixel value: %d\n", firstRow[0]);
//8:每个通道占8位
//U:表示无符号
//C:表示char类型
//3:表示通道数目是3
Mat M(3, 3, CV_8UC3, Scalar(0, 0, 255));
Mat m1;
m1.create(src.size(), src.type());
m1 = Scalar(0, 0, 255);
//定义卷积核
Mat kernel = (Mat_<char>(3, 3) << 0, -1, 0, -1, 6, -1, 0, -1, 0);
//定义对角矩阵
Mat m2 = Mat::eye(2, 2, CV_8UC1);
waitKey(0);
return 0;
}