I. Reading and writing of pictures
(1) Imread (Src,int flag); where SRC is the path where the image is read, flag is the grayscale setting for the picture, which is preferable to the following values:
enum{/* 8bit, color or not */cv_load_image_unchanged =-1,//This identity is abandoned in the new version, ignoring/* 8bit, Gray */Cv_load_image_grayscale = 0,//If you take this identifier, always convert the image to grayscale 1/*, color */Cv_load_image_color = 1,//If this logo is taken, the image is always converted into a color integrated/* Any depth,? */cv_load_image_anydepth = 2,//If you take this identifier, if the image is loaded with a depth of 16 or 32 bits, the image of the corresponding depth is returned, otherwise it is converted to a 8-bit image and returned/*, any color */Cv_load_image_anycolor = 4};
(2) imread (imagename,image); where SRC is the path to read the picture, and flag is the grayscale setting for the picture, the following values are desirable:
Imshow ("3" logo map, logo);
(3) channel separation, Split (Srcimage,channels), wherein srcimage for the processing of picture objects, channels for the separation of three channels;
(4) Separation of color after the channel separation, imagebluechannel=channels.at (0); Separating the blue channel
(5) Weighted overlay processing of images; Addweighted (Imagebluechannel (Rect (0,0,logoimage.cols,logoimage.rows)), 0.5,logoimage,0.5,0.,
Imagebluechannel (Rect (0,0,logoimage.cols,logoimage.rows)));
- void addweighted (Inputarray src1, double alpha, Inputarray src2, double beta, double gamma, outputarray DST, int dtype=-1) ;
- The first argument, the Inputarray type of SRC1, represents the first array that needs to be weighted, often filled with a mat.
- The second argument, alpha, represents the weight of the first array
- A src2 that represents the second array, which needs to have the same size and number of channels as the first array
- The fourth parameter, beta, represents the weight value of the second array
- The fifth parameter, DST, the output array, and the input two arrays have the same size and number of channels.
- The seventh parameter, Dtype, the selectable depth of the output array, has a default value of 1.; When two input arrays have the same depth, this parameter is set to-1 (the default), which is equivalent to src1.depth ()
(6) The separated channel is mixed with the picture, merge (Channels,srcimage);
(7) Reset the image size; Resize (srcimage,sizeimage1,size (950,600), 0,0,cv_inter_linear), which sets the srcimage image size to 950*600,
After processing, assign value to SizeImage1;
(8) Case
BOOL Multichannelblending () {Mat srcimage; Define variable Mat logoimage;vector<mat>channels; Defines an array of channel mat structures Mat Imagebluechannel; Mat sizeimage1;logoimage=imread ("D:\\Program files\\opencvtest\\opencvtest1\\pic\\hualogo.jpg", 0); Load the picture and assign it to Logoimage, where the second parameter is not srcimage=imread when using three channels ("D:\\Program files\\opencvtest\\opencvtest1\\pic\\ Huage.jpg "); Load the picture and assign the value to Srcimageif (!logoimage.data) {printf ("Oh,no, read logoimage Error ~! \ n "); return false; }if (!srcimage.data) {printf ("Oh, no, read srcimage error 1~");} Split (srcimage,channels);//separate the color channel, convert a 3-channel image into 3 single-channel image imagebluechannel=channels.at (0); Separates the blue channel addweighted (Imagebluechannel (Rect (0,0,logoimage.cols,logoimage.rows)), 0.5,logoimage,0.5,0., Imagebluechannel (Rect (0,0,logoimage.cols,logoimage.rows))); Merge (Channels,srcimage); Resize (srcimage,sizeimage1,size (950,600), 0,0,cv_inter_linear); Reset the image size and assign it to Sizeimage1namedwindow ("Hua elder brother beauty shone +logo blue channel by Tina"); Imshow ("Hua elder brother beauty shone +logo blue channel by Tina", SizeImage1); Mat Imagegreenchannel; Logoimage=imread ("D:\\Program files\\Opencvtest\\opencvtest1\\pic\\hualogo.jpg ", 0); Srcimage=imread ("D:\\Program files\\opencvtest\\opencvtest1\\pic\\huage.jpg"); if (!logoimage.data) {printf ("Oh,no, read logoimage Error ~! \ n "); return false; } if (!srcimage.data) {printf ("Oh,no, read srcimage Error ~! \ n "); return false; } split (srcimage,channels);//Separate color channel imagegreenchannel=channels.at (1); Detach greenaddweighted (Imagegreenchannel (Rect (0,0,logoimage.cols,logoimage.rows)), 0.0,logoimage,0.5,0., Imagegreenchannel (Rect (0,0,logoimage.cols,logoimage.rows))); Merge (Channels,srcimage); Resize (srcimage,sizeimage1,size (950,600), 0,0,cv_inter_linear); Namedwindow ("Hua elder brother Beauty shone +logo green channel by Tina"); Imshow ("Hua elder brother Beauty Zhao +logo green channel by Tina", SizeImage1); Mat Imageredchannel; Logoimage=imread ("D:\\Program files\\opencvtest\\opencvtest1\\pic\\hualogo.jpg", 0); Srcimage=imread ("D:\\Program files\\opencvtest\\opencvtest1\\pic\\huage.jpg"); if (!logoimage.data) {printf ("Oh,no, read logoimage Error ~! \ n "); return false; } if (!srcimage.data) {printf ("Oh,no, read srcimage Error ~! \ n "); return false; } split (srcimage,channels);//separating The color channel imageredchannel=channels.at (2);//separating The Red channel addweighted (Imageredchannel (Rect (0,0, logoimage.cols,logoimage.rows)), 0.0,logoimage,0.5,0.,imageredchannel (Rect (0,0,logoimage.cols,logoimage.rows))) ; Merge (Channels,srcimage); Resize (srcimage,sizeimage1,size (950,600), 0,0,cv_inter_linear);//reset the picture size Namedwindow ("Hua elder brother beauty shone +logo red channel by Tina"); Imshow ("Hua elder brother beauty shone +logo red channel by Tina", SizeImage1); return true; }
Run the result diagram:
Open CV Beginner (i)