(19)边界变幻
说实话,我真不知道,这个有啥用,先记着吧,以后可能慢慢理解
详细可以看这个代码:https://blog.****.net/qq_39396954/article/details/80522426
=======================================
1 #include <opencv2\core\core.hpp> 2 #include <opencv2\highgui\highgui.hpp> 3 #include <opencv2\imgproc\imgproc.hpp> 4 #include <opencv2\objdetect\objdetect.hpp> 5 #include <opencv2\imgproc\types_c.h> 6 #include <opencv2\objdetect\objdetect_c.h> 7 #include<opencv2/opencv.hpp> 8 #include<iostream> 9 #include<cmath> 10 #include<cstdio> 11 12 using namespace std; 13 using namespace cv; 14 15 int main() 16 { 17 Mat src, dst; 18 src = imread("C:\\Users\\32829\\Desktop\\aa.jpg"); 19 if (src.empty()) 20 { 21 cout << "!!???" << endl; 22 return -1; 23 } 24 namedWindow("cat!", 1); 25 imshow("cat!", src); 26 namedWindow("out", 1); 27 28 int top = (int)(0.05*src.rows); 29 int bottom = (int)(0.05*src.rows); 30 int left = (int)(0.05*src.cols); 31 int right = (int)(0.05*src.cols); 32 RNG rng(12345); 33 int bordertype = BORDER_DEFAULT; 34 35 int c = 0; 36 while (true) 37 { 38 c = waitKey(500); 39 if ((char)c == 27) 40 break; 41 if ((char)c == 'r') 42 { 43 bordertype = BORDER_REPLICATE; 44 } 45 else if ((char)c == 'w') 46 { 47 bordertype = BORDER_WRAP; 48 } 49 else if ((char)c == 'c') 50 { 51 bordertype = BORDER_CONSTANT; 52 } 53 57 Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)); 58 copyMakeBorder(src, dst, top, bottom, left, right, bordertype, color); 59 imshow("out", dst); 60 } 61 62 63 waitKey(0); 64 return 0; 65 }
开始运行,是用和原图没啥差别,然后按下===>r ,就代表用周围的像素来代替边界的像素,最后的结果是这样
============================
====================================
这是按下-->w键,,,是换行,就是用下代表上,用左代表右,用右代表左,就是上下和左右颠倒
======================================
================================
按下c,是代表constant的,他的边框是一直变化的。
===================================