#include <iostream>
#include<opencv2/opencv.hpp>
#include "math.h"
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat src,dst;//初始化一个操作对象
src = imread("C:/Users/JAY/Desktop/Others/tang.jpg");
if (!src.data)//判断图片是否加载进来
{
cout << "不能加载图片" << endl;
return -1;
}
namedWindow("加载的图片", WINDOW_AUTOSIZE);
imshow("加载的图片", src);//""内命名一致,才能显示在一个窗口
int top = (int)(0.05*src.rows);
int botton = (int)(0.05*src.rows);
int left = (int)(0.05*src.cols);
int right = (int)(0.05*src.cols);
RNG rng(12345);
int borderType = BORDER_DEFAULT;
int c = 0;
while (true)
{
c = waitKey(500);
if ((char)c==27)
{
break;
}
if ((char)c=='r')//键盘输入对应键,显示不同效果
{
borderType = BORDER_REPLICATE;//插值计算
}
else if ((char)c == 'v')
{
borderType = BORDER_WRAP;
}
else if ((char)c == 'c')
{
borderType = BORDER_CONSTANT;
}
else
{
borderType = BORDER_DEFAULT;//一般选择默认的,效果好
}
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
copyMakeBorder(src, dst, top, botton, left, right, borderType);
imshow("重绘边缘图案", dst);
}
waitKey(0);
return 0;
}
结果
默认BORDER_DEFAULT
BORDER_REPLICATE
BORDER_WRAP
BORDER_CONSTANT