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
+
37
+ #include < opencv2/core.hpp>
38
+ #include < opencv2/core/utility.hpp>
39
+ #include < opencv2/highgui.hpp>
40
+ #include < opencv2/ximgproc.hpp>
41
+ #include " opencv2/ximgproc/paillou_filter.hpp"
42
+
43
+ using namespace cv ;
44
+ using namespace cv ::ximgproc;
45
+
46
+ #include < iostream>
47
+ using namespace std ;
48
+
49
+ int aa = 100 , ww = 10 ;
50
+ Mat dx, dy;
51
+ UMat img;
52
+ const char * window_name = " Gradient Modulus" ;
53
+
54
+ static void DisplayImage (Mat x,string s)
55
+ {
56
+ vector<Mat> sx;
57
+ split (x, sx);
58
+ vector<double > minVal (3 ), maxVal (3 );
59
+ for (int i = 0 ; i < static_cast <int >(sx.size ()); i++)
60
+ {
61
+ minMaxLoc (sx[i], &minVal[i], &maxVal[i]);
62
+ }
63
+ maxVal[0 ] = *max_element (maxVal.begin (), maxVal.end ());
64
+ minVal[0 ] = *min_element (minVal.begin (), minVal.end ());
65
+ Mat uc;
66
+ x.convertTo (uc, CV_8U,255 /(maxVal[0 ]-minVal[0 ]),-255 *minVal[0 ]/(maxVal[0 ]-minVal[0 ]));
67
+ imshow (s, uc);
68
+ }
69
+
70
+
71
+ /* *
72
+ * @function paillouFilter
73
+ * @brief Trackbar callback
74
+ */
75
+ static void PaillouFilter (int , void *)
76
+ {
77
+ Mat dst;
78
+ double a=aa/100.0 ,w=ww/100.0 ;
79
+ Mat rx,ry;
80
+ GradientPaillouX (img,rx,a,w);
81
+ GradientPaillouY (img,ry,a,w);
82
+ DisplayImage (rx, " Gx" );
83
+ DisplayImage (ry, " Gy" );
84
+ add (rx.mul (rx),ry.mul (ry),dst);
85
+ sqrt (dst,dst);
86
+ DisplayImage (dst, window_name );
87
+ }
88
+
89
+
90
+ int main (int argc, char * argv[])
91
+ {
92
+ if (argc==2 )
93
+ imread (argv[1 ]).copyTo (img);
94
+ if (img.empty ())
95
+ {
96
+ cout << " File not found or empty image\n " ;
97
+ }
98
+ imshow (" Original" ,img);
99
+ namedWindow ( window_name, WINDOW_AUTOSIZE );
100
+
101
+ // / Create a Trackbar for user to enter threshold
102
+ createTrackbar ( " a:" ,window_name, &aa, 400 , PaillouFilter );
103
+ createTrackbar ( " w:" , window_name, &ww, 400 , PaillouFilter );
104
+ PaillouFilter (0 ,NULL );
105
+ waitKey ();
106
+ return 0 ;
107
+ }
0 commit comments