#include<iostream>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
Mat src, dst;
int top, buttom, left1, right1;
Scalar value;
int borderType;
RNG rng(12345);
char* window_name = "copyMakeBorder Demo";
int main()
{
src = imread("奥巴马.jpg");
if (!src.data)
{
cerr << "Can't open the image!" << endl;
return EXIT_FAILURE;
}
int c;
namedWindow(window_name);
top = (int)(0.05*src.rows);
buttom = (int)(0.05*src.rows);
left1 = (int)(0.05*src.cols);
right1 = (int)(0.05*src.cols);
dst = src;
imshow(window_name, dst);
while (true)
{
c = waitKey(500);
if ((char)c == 27)
{
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, buttom, left1, right1, borderType, value);
imshow(window_name,dst);
}
return 0;
}