OpenCV realize their linear filter

 

 1 #include "opencv2/imgproc/imgproc.hpp"
 2 #include "opencv2/highgui/highgui.hpp"
 3 #include <stdlib.h>
 4 #include <stdio.h>
 5 
 6 using namespace cv;
 7 
 8 /** @函数main */
 9 int main ( int argc, char** argv )
10 {
11   /// 声明变量
12   Mat src, dst;
13 
14   Mat kernel;
15   Point anchor;
16   Double Delta;
 . 17    int ddepth;
 18 is    int kernel_size;
 . 19    char * window_name = " filter2D Demo " ;
 20 is  
21 is    int C;
 22 is  
23 is    /// Loading image 
24    the src = imread (the argv [ . 1 ]);
 25  
26 is    IF (! src.data)
 27    { return - . 1 ;}
 28  
29    /// creation window 
30    namedWindow (window_name, CV_WINDOW_AUTOSIZE);
 31 is  
32   /// initialization parameters of the filter 
33 is    Anchor Point = (- . 1 , - . 1 );
 34 is    Delta = 0 ;
 35    ddepth = - . 1 ;
 36  
37 [    /// cycle - every 0.5 seconds, with a different image of a nucleus filter 
38 is    int IND = 0 ;
 39    the while ( to true )
 40      {
 41 is        C = waitKey ( 500 );
 42 is        /// press 'ESC' to exit the program 
43 is        IF (( char ) == C 27 )
 44 is          {BREAK ;}
 45  
46 is        /// Update normalized size of the block core filter 
47        kernel_size = . 3 + 2 * (% IND . 5 );
 48        Kernel Mat :: = ones (kernel_size, kernel_size, CV_32F) / ( a float ) ( * kernel_size kernel_size);
 49  
50        /// using a filter 
51 is        filter2D (the src, DST, ddepth, Kernel, Anchor, Delta, BORDER_DEFAULT);
 52 is        imshow (window_name, DST);
 53 is        IND ++ ;
 54 is      }
 55  
56 is    return  0 ;
 57 is }

Guess you like

Origin www.cnblogs.com/ybqjymy/p/12170907.html