OPENCV 各种模糊+Trackbar

来源:互联网 发布:淘宝开通网商银行账户 编辑:程序博客网 时间:2024/05/16 18:28
/*** file Smoothing.cpp* brief Sample code for simple filters* author OpenCV team*/#include <iostream>#include <vector>#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/highgui/highgui.hpp"using namespace std;using namespace cv;/*/// Global Variablesint DELAY_CAPTION = 1500;int DELAY_BLUR = 100;int MAX_KERNEL_LENGTH = 31;Mat src; Mat dst;char window_name[] = "Smoothing Demo";int filterTpye = 1;int size = 1;int maxFilterType  = 4;int maxsize = 50;Mat img,dst;string windowName = "opencv_filter";void onFileterChange(int , void *){cout<<filterTpye<<endl;if (size%2==0)  //size是偶数,把它减1变为奇数{size-=1;}if(size <= 0 ){size = 1;}cout<<size<<endl;switch(filterTpye){case 1:blur(img,dst,Size(size,size));break;case 2:GaussianBlur(img,dst,Size(size,size),0,0);break;case 3:medianBlur(img,dst,size);break;case 4:bilateralFilter(img,dst,size,size*2,size/2);break;default:cout<<"illeagal number"<<endl;break;}imshow(windowName,dst);}int main( ){string trackbarName ="type of blur"; img = imread("C:\\lena.jpg");dst = img.clone();namedWindow(windowName,1);createTrackbar(trackbarName, windowName,&filterTpye, maxFilterType, onFileterChange);string filterSizeName = "filter Size";createTrackbar(filterSizeName, windowName,&size, maxsize, onFileterChange);onFileterChange(0,0);waitKey(0);return 0;}

0 0
原创粉丝点击