#include
#include
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat src = imread("E:/4.png");
if (src.empty()) {
cout << "can not load" << endl;
}
else {
cout << "successful" << endl;
}
namedWindow("test opencv setup", CV_WINDOW_AUTOSIZE);
imshow("test opencv setup", src);
waitKey(0);
return 0;
}
//使用mat来创建矩阵
Mat dst;
dst = Mat(src.size(), src.type());
dst = Scalar(127, 0, 255);
namedWindow("test2", CV_WINDOW_AUTOSIZE);
imshow("test2", dst);
Mat dst1;
src.copyTo(dst1);
namedWindow("test3", CV_WINDOW_AUTOSIZE);
imshow("test3", dst1);
//cvtColor()进行颜色通道转换
Mat dst2;
cvtColor(src, dst2, CV_BGR2GRAY);
cout << "src channels " << src.channels() << endl;
cout << "dst2 channels " << dst2.channels() << endl;
namedWindow("test4", CV_WINDOW_AUTOSIZE);
imshow("test4", dst2);
//获取图像的行列
int col = dst1.cols;
int row = dst2.rows;
int nn = dst1.channels();
//像素指针操作
const uchar* firstRow = dst2.ptr
printf("fist pixel value : %d\n", *firstRow);
cout << "the (1,20) pixel: " << firstRow[19] << endl;
Mat M(100, 100, CV_8UC1, Scalar(127));
namedWindow("test5", CV_WINDOW_AUTOSIZE);
imshow("test5", M);
//使用create来创建
Mat m1;
m1.create(src.size(), src.type());
m1 = Scalar(0, 0, 255);
namedWindow("test6", CV_WINDOW_AUTOSIZE);
imshow("test6", m1);
Mat dst00;
Mat kernel = (Mat_
filter2D(src, dst00, -1, kernel);
namedWindow("test7", CV_WINDOW_AUTOSIZE);
imshow("test7", dst00);
Mat m2;
m2 = Mat::eye(2, 2, CV_8UC1);
cout << "m2 =" << endl << m2 << endl;
imshow("output", m2);