OpenCV computer vision display image

#include <iostream>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;
using namespace cv;

int main()
	Mat img;
	//Mat imread( const string& filename, int flags=1 );
	img = imread("1.jpg",1);

		cout << "read image failed!" << endl;
		return 1;
	//void imshow(const string& winname, InputArray mat);
	imshow("show a image", img);
	cout << img.rows << '*' << img.cols << endl;
	cout << img.channels() << endl;

	return 0;

shows the effect as follows:

Mat imread( const string& filename, int flags=1 ); this function has two input parameters, the first one is the file name, the second one is Read mode, the default value is 1, so you can not enter this parameter; when the flags use the default parameters, all three-channel images are entered; when the flags input parameter is 0, the single-channel grayscale is read. Figure Therefore, according to this function, the method of displaying a single-channel grayscale image has the following two operations: The first method:

img = imread("1.jpg",0);

The second method:

#include <opencv2/imgproc/imgproc.hpp>

img = imread("1.jpg",1);
//void cvtColor( InputArray src, OutputArray dst, int code, int dstCn=0 );
cvtColor(img, img, CV_RGB2GRAY);

The two methods display the following results:

The above two methods result the same, but in terms of simplicity, it is still the first The method is convenient and can be done with just one sentence.