copyMakeBorder(src,dst,top,bottom,left,right,borderType,value);
borderType有两种
- BORDER_CONSTANT
- BORDER_REPLICATE
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
Mat src, dst;
int top0, bottom0, left0, right0;
int borderType;
Scalar value;
String window_name="copyMakeBorder Demo";
RNG rng(12345);
int main()
{
Mat src=imread("image.jpg");
int c;
namedWindow(window_name,WINDOW_AUTOSIZE);
top0=(int)(0.05*src.rows);
bottom0=(int)(0.05*src.rows);
left0=(int)(0.05*src.cols);
right0=(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,top0,bottom0,left0,right0,borderType,value);
imshow(window_name,dst);
}
return 0;
}
实验截图
以上两张为BORDER_CONSTANT结果
以上为BORDER_REPLICATE结果