Reference learning website: blog.csdn.net/column/deta… 1. CV ::Mat class is a data structure used to store images and other matrix data. 2. Imread function loads images

Use imread to open image for Mat class eg:

Mat myMat= imread("dota.jpg");
Copy the code

The picture is in the project directory

3. NamedWindow function is used to create window 4. Imshow function displays an image in the specified window. The window name in nameWindows and imshow should be the same otherwise there will be two Windows and imshow itself will create the window eg:

NamedWindow (" form "); Imshow (" form ", image); // The second argument is the Mat object, which is the imageCopy the code

5. The imwrite function writes the image to a file

Imwrite (" image.png ", mat); // The second argument is the Mat object, which is the graph to write to the fileCopy the code

6.ROI Region Divide a region on the image

Mat imageROI; / / define a Mat object is used to specify a method of / / a image represents the image of the image after the first two parameters position on two parameters is the regional aspect imageROI = image (the Rect (500250, logo. Cols, logo. The rows)); // Method two: image: image; Range: image; Range: image; Range: image ImageROI = image (Range (250250 + logo. Rows), Range (200200 + logo. Cols));Copy the code

Example of picture overlay

Mat srcImage1= imread("beijing".jpg"); Mat logoImage= imread("logo.jpg"); / / define a Mat type and set to its ROI area Mat imageROI = srcImage1 (the Rect (200250, logoImage. Cols, logoImage. Rows)); Mat mask= imread("dota_logo.jpg",0); // [4] Copy logoImage to imageROI logoImage. CopyTo (imageROI,mask); // Since imageROI is the region on srcImage1, the overlay is completeCopy the code

7. AddWeighted function

AddWeighted (srcImage1, alphaValue, srcImage2, betaValue, 0.0, dstImage); DST = src1*alpha+ src2*beta + gamma; The penultimate parameter is the offset. It is usually 0.0 // and the two must be the same size and depthCopy the code

The spilt function has two prototypes

C++: void split(const mat&src, Mat*mvbegin); // const mat&src, Mat*mvbegin; C++: void split(InputArray m,OutputArrayOfArrays mv);Copy the code

eg:

vector<Mat> channels; Mat imageBlueChannel; Mat imageGreenChannel; Mat imageRedChannel; srcImage4= imread("dota.jpg"); // Convert a 3-channel image into 3 single-channel images split(srcImage4,channels); ImageBlueChannel = channels.at(0); imageGreenChannel = channels.at(1); imageRedChannel = channels.at(2);Copy the code

So the inverse of spilt also has two prototypes

++: void merge(const Mat* mv, size_tcount, OutputArray DST) Void Merge (InputArrayOfArrays MV,OutputArray DST) // Single-channel image array outputCopy the code