这段程序来自OpenCV教程,使用copyMakeBorder函数来给图像加上边框:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat image,result;
//获得边界的类型
int borderType = BORDER_REPLICATE;
//输入字符
int c;
image = imread("D:/picture/img.tif");
if(!image.data)
{
printf("fail to load image\n");
return -1;
}
//使用说明
cout<<"使用说明:"<<endl;
cout<<"按键c设置边界为随机的颜色"<<endl;
cout<<"按键r设置边界为原图的颜色"<<endl;
cout<<"按键按键ESC退出程序"<<endl;
//颜色随机值
Scalar value;
//随机数种子
RNG rng(12345);
//初始化参数:边框的粗细
int top = (int) (0.05*image.rows);
int bottom = (int) (0.05*image.rows);
int left = (int) (0.05*image.cols);
int right = (int) (0.05*ima