边缘处理
1、边缘处理
增加图像边缘api:
2、代码实现
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat img = imread("G:/testpic/img.png");
if (img.empty())
{
printf("cannot load the image");
return 0;
}
namedWindow("input", WINDOW_AUTOSIZE);
imshow("input", img);
//
int c = 0;
int top = (int)(0.1 * img.rows);
int bottom = (int)(0.1 * img.rows);
int left = (int)(0.1 * img.cols);
int right = (int)(0.1 * img.cols);
Mat dst;
RNG rng(123545);
while(true)
{
c = waitKey(500);
if ((char) c == 27)
{
break;
}
else if((char) c == "w")
{
border_type = BORDER_WRAP;
}
else if((char) c == "r")
{
border_type = BORDER_REPLICATE;
}
else if((char) c == "c")
{
border_type = BORDER_CONSTANT;
}
else
{
border_type = BORDER_DEFAULT;
}
Scalar color = Scalar(rng.uniform(0,255), rng.unform(0,255), rng.uniform(0,255));
copyMakeBorder(img, dst, top, bottom, left, right, border_type, color);
imshow("output", dst);
}
return 0;
}
原图
border_Constant
border_Replicate
border_wrap