1
+ /*
2
+ * By downloading, copying, installing or using the software you agree to this license.
3
+ * If you do not agree to this license, do not download, install,
4
+ * copy or use the software.
5
+ *
6
+ *
7
+ * License Agreement
8
+ * For Open Source Computer Vision Library
9
+ * (3 - clause BSD License)
10
+ *
11
+ * Redistribution and use in source and binary forms, with or without modification,
12
+ * are permitted provided that the following conditions are met :
13
+ *
14
+ * *Redistributions of source code must retain the above copyright notice,
15
+ * this list of conditions and the following disclaimer.
16
+ *
17
+ * * Redistributions in binary form must reproduce the above copyright notice,
18
+ * this list of conditions and the following disclaimer in the documentation
19
+ * and / or other materials provided with the distribution.
20
+ *
21
+ * * Neither the names of the copyright holders nor the names of the contributors
22
+ * may be used to endorse or promote products derived from this software
23
+ * without specific prior written permission.
24
+ *
25
+ * This software is provided by the copyright holders and contributors "as is" and
26
+ * any express or implied warranties, including, but not limited to, the implied
27
+ * warranties of merchantability and fitness for a particular purpose are disclaimed.
28
+ * In no event shall copyright holders or contributors be liable for any direct,
29
+ * indirect, incidental, special, exemplary, or consequential damages
30
+ * (including, but not limited to, procurement of substitute goods or services;
31
+ * loss of use, data, or profits; or business interruption) however caused
32
+ * and on any theory of liability, whether in contract, strict liability,
33
+ * or tort(including negligence or otherwise) arising in any way out of
34
+ * the use of this software, even if advised of the possibility of such damage.
35
+ */
36
+ #include < opencv2/core.hpp>
37
+ #include < opencv2/core/utility.hpp>
38
+ #include < opencv2/highgui.hpp>
39
+ #include < opencv2/ximgproc.hpp>
40
+ #include " opencv2/ximgproc/deriche_filter.hpp"
41
+
42
+ using namespace cv ;
43
+ using namespace cv ::ximgproc;
44
+
45
+ #include < iostream>
46
+ using namespace std ;
47
+
48
+ int alDerive=100 ;
49
+ int alMean=100 ;
50
+ Ptr <Mat> img;
51
+ const string & winName = " Gradient Modulus" ;
52
+
53
+ static void DisplayImage (Mat x,string s)
54
+ {
55
+ vector<Mat> sx;
56
+ split (x, sx);
57
+ vector<double > minVal (3 ), maxVal (3 );
58
+ for (size_t i = 0 ; i < sx.size (); i++)
59
+ {
60
+ minMaxLoc (sx[i], &minVal[i], &maxVal[i]);
61
+ }
62
+ maxVal[0 ] = *max_element (maxVal.begin (), maxVal.end ());
63
+ minVal[0 ] = *min_element (minVal.begin (), minVal.end ());
64
+ Mat uc;
65
+ x.convertTo (uc, CV_8U,255 /(maxVal[0 ]-minVal[0 ]),-255 *minVal[0 ]/(maxVal[0 ]-minVal[0 ]));
66
+ imshow (s, uc);
67
+ }
68
+
69
+
70
+ /* *
71
+ * @function DericheFilter
72
+ * @brief Trackbar callback
73
+ */
74
+ static void DericheFilter (int , void *)
75
+ {
76
+ Mat dst;
77
+ double d=alDerive/100.0 ,m=alMean/100.0 ;
78
+ Mat rx,ry;
79
+ GradientDericheX (*img.get (),rx,d,m);
80
+ GradientDericheY (*img.get (),ry,d,m);
81
+ DisplayImage (rx, " Gx" );
82
+ DisplayImage (ry, " Gy" );
83
+ add (rx.mul (rx),ry.mul (ry),dst);
84
+ sqrt (dst,dst);
85
+ DisplayImage (dst, winName );
86
+ }
87
+
88
+ int main (int argc, char * argv[])
89
+ {
90
+ Mat *m=new Mat;
91
+ cv::CommandLineParser parser (argc, argv, " {help h | | show help message}{@input | | input image}" );
92
+ if (parser.has (" help" ))
93
+ {
94
+ parser.printMessage ();
95
+ return -1 ;
96
+ }
97
+ string input_image = parser.get <string>(" @input" );
98
+ if (input_image.empty ())
99
+ {
100
+ parser.printMessage ();
101
+ parser.printErrors ();
102
+ return -2 ;
103
+ }
104
+ if (argc==2 )
105
+ *m = imread (input_image);
106
+ if (m->empty ())
107
+ {
108
+ cout << " File not found or empty image\n " ;
109
+ return -3 ;
110
+ }
111
+ imshow (" Original" , *m);
112
+ img =Ptr <Mat>(m);
113
+ namedWindow ( winName, WINDOW_AUTOSIZE );
114
+ // / Create a Trackbar for user to enter threshold
115
+ createTrackbar ( " Derive:" ,winName, &alDerive, 400 , DericheFilter );
116
+ createTrackbar ( " Mean:" , winName, &alMean, 400 , DericheFilter );
117
+ DericheFilter (0 ,NULL );
118
+ waitKey ();
119
+ return 0 ;
120
+ }
0 commit comments