2
* @file copyMakeBorder_demo.cpp
3
* @brief Sample code that shows the functionality of copyMakeBorder
7
#include "opencv2/imgproc/imgproc.hpp"
8
#include "opencv2/imgcodecs.hpp"
9
#include "opencv2/highgui/highgui.hpp"
17
int top, bottom, left, right;
19
const char* window_name = "copyMakeBorder Demo";
25
int main( int, char** argv )
31
src = imread( argv[1] );
35
printf(" No data entered, please enter the path to an image file \n");
39
/// Brief how-to for this program
40
printf( "\n \t copyMakeBorder Demo: \n" );
41
printf( "\t -------------------- \n" );
42
printf( " ** Press 'c' to set the border to a random constant value \n");
43
printf( " ** Press 'r' to set the border to be replicated \n");
44
printf( " ** Press 'ESC' to exit the program \n");
47
namedWindow( window_name, WINDOW_AUTOSIZE );
49
/// Initialize arguments for the filter
50
top = (int) (0.05*src.rows); bottom = (int) (0.05*src.rows);
51
left = (int) (0.05*src.cols); right = (int) (0.05*src.cols);
54
imshow( window_name, dst );
62
else if( (char)c == 'c' )
63
{ borderType = BORDER_CONSTANT; }
64
else if( (char)c == 'r' )
65
{ borderType = BORDER_REPLICATE; }
67
Scalar value( rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255) );
68
copyMakeBorder( src, dst, top, bottom, left, right, borderType, value );
70
imshow( window_name, dst );