Build boundaries;
Because the pixels at the edge of the image are not calculated according to the formula when making the convolution, it is necessary to construct the boundary at the edge to calculate;
The functions for constructing boundaries in OpenCV are: Copymakeborder (src,dst,top,bottom,left,right,bordertype,values);
First come the code:
1#include <opencv2/opencv.hpp>2#include <iostream>3#include <string>4 5 using namespacestd;6 using namespaceCV;7 8 intMainintargcChar**argv)9 {Ten if((argc-2)!=0) One { Acout<<"Usage:./makeborder \ "Image_name\""<<Endl; - return 0; - } the -Mat Src=imread (argv[1]); - if(Src.empty ()) - { +cout<<"Have not found image"<<Endl; - return-1; + } A atNamedwindow ("SRC", cv_window_autosize); -Imshow ("SRC", SRC); - - Mat DST; -RNG RNG (12345); - Scalar values; in inttop; - intBottom; to intLeft ; + intRight ; - CharC; the intBordertype; * $Top= (int)(0.05*src.rows);Panax NotoginsengBottom= (int)(0.05*src.rows); -Left= (int)(0.05*src.cols); theRight= (int)(0.05*src.rows); + A while(true) the { +C=waitkey ( -); - if((Char) c== -) $ Break; $ //bordertype=border_constant; -Bordertype=border_replicate; -Values=scalar (Rng.uniform (0,255), Rng.uniform (0,255), Rng.uniform (0,255)); the Copymakeborder (src,dst,top,bottom,left,right,bordertype,values); - WuyiNamedwindow ("Dst", cv_window_autosize); theImshow ("Dst", DST); - } Wu - Waitkey (); About return 0; $}
The same CMakeLists.txt
1 2.8 )2Project (makeBorder.cpp)3find_package (OpenCV REQUIRED)4 add_executable (Makeborder makeBorder.cpp) 5 target_link_libraries (Makeborder ${opencv_libs})
When the Borderype types are evaluated separately, the results are:
You can see that the two parameters differ in that the former is populated with self-built pixels, which expand the edge pixels. Of course, it looks like the latter is more attractive.
The description of the function parameters is not much, literally can be understood.
Above.
OPENCV Official Document Learning record (12)