void copyMakeBorder(
InputArray src, 输入
OutputArray dst, 输出
int top, 上边框
int bottom, 下边框
int left, 左边框
int right, 右边框
int borderType, 边框类型
const Scalar& value=Scalar() 填充颜色
)
常用的边框类型:
BORDER_CONSTANT - 填充指定像素
BORDER_REPLICATE - 用已知的边缘像素值
BORDER_WRAR - 用另外一边填充
其它见 opencv学习六
#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
char file[] = "1.jpg";
int main(int argc, char** argv)
{
Mat img = imread(file, -1);
pyrDown(img, img, Size(img.cols/2, img.rows/2));
imshow("1",img);
Mat out;
copyMakeBorder(img, out, 10, 10, 10, 10, BORDER_REPLICATE);
imshow("2",out);imwrite("2.jpg", out);
waitKey();
return 1;
}
原图
2.jpg