Fill the border of the image for filtering, convolution, and other operations related to image boundary processing.
# Include "opencv2/imgproc. HPP "# include" opencv2/highgui. HPP "# include <stdlib. h> # include <stdio. h> using namespace CV; // global variable mat SRC, DST; int top, bottom, left, right; // defines the boundary size int bordertype; // The boundary processing type scalar value; char * window_name = "copymakeborder Demo"; RNG (12345); int main (INT argc, char ** argv) {int C; // load the image src = imread (argv [1]); If (! SRC. data) {return-1; printf ("no data entered, please enter the path to an image file \ n ");} /// brief how-to for this program printf ("\ n \ t copymakeborder Demo: \ n"); printf ("\ t ------------------ \ n "); printf ("** press 'C' to set the border to a random constant value \ n "); printf ("** press 'R' to set the border to be replicated \ n"); printf ("** press 'esc 'to exit the program \ n "); // create a window named window (window_name, cv_window_autosize); // initialize the filter parameter Top = (INT) (0.05 * SRC. rows); bottom = (INT) (0.05 * SRC. rows); left = (INT) (0.05 * SRC. cols); Right = (INT) (0.05 * SRC. cols); DST = SRC; imshow (window_name, DST); While (true) {c = waitkey (500); If (char) C = 27) // Press ESC to exit the program {break;} else if (char) C = 'C') {bordertype = border_constant;} else if (char) C = 'R') {bordertype = border_replicate;} value = scalar (RNG. uniform (0,255), RNG. uniform (0,255), RNG. uniform (0,255); copymakeborder (SRC, DST, top, bottom, left, right, bordertype, value); imshow (window_name, DST);} return 0 ;}