OpenCV基础课程笔记17卷积边缘处理
写在前面
copyMakeBorder()
其中,处理边缘的三种方式:
BORDER_CONSTANT 指定像素填充
BORDER_REPLICATE 已知像素(周围的像素)填充
BORDER_WRAP 另一边的像素填充
和贾志刚老师学的一个键盘事件,通过按键改变
代码
#include<iostream>
#include<opencv2/opencv.hpp>
#include<cmath>
using namespace std;
using namespace cv;
int main() {
Mat src = imread("A:\\专用\\TestForTheCV\\class17影流之主放大.jpg");
Mat dst;
imshow("图片", src);
int top = (int)src.cols*0.05;
int left = (int)src.rows*0.05;
int right = left, bottom = top;
RNG rng = RNG(123);
int borderType = BORDER_DEFAULT;
char OUTPUT[] = "bordered";
namedWindow(OUTPUT, CV_WINDOW_AUTOSIZE);
GaussianBlur(src, dst, Size(15, 15), 21, 21,BORDER_REPLICATE);
imshow("高斯模糊", dst);
int c = 0;
while (true) {
c = waitKey(500);
//ESC
if ((char)c ==27)break;
else if ((char)c == 'c')borderType = BORDER_CONSTANT;
else if ((char)c == 'r')borderType = BORDER_REPLICATE;
else if ((char)c == 'w')borderType = BORDER_WRAP;
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
copyMakeBorder(src, dst, top, bottom, left, right, borderType, color);
imshow(OUTPUT, dst);
}
waitKey(0);
return 0;
}
运行结果
用已知像素(周围像素)填充

用另一边的像素填充

用指定像素填充
(写了一个for循环,每次变换不同的颜色)
来,让我们高唱:如果让你重新来过你会不会爱我~~





浙公网安备 33010602011771号