@@ -46,21 +46,17 @@ using namespace cv::ximgproc;
46
46
#include < iostream>
47
47
using namespace std ;
48
48
49
- int lowThreshold=20 ;
50
- int maxThreshold=20 ;
51
- int const max_lowThreshold = 500 ;
52
49
int alDerive=100 ;
53
50
int alMean=100 ;
54
- Mat dx, dy;
55
- UMat img;
56
- const char * window_name = " Gradient Modulus" ;
51
+ Mat img;
52
+ const string & winName = " Gradient Modulus" ;
57
53
58
- static void DisplayImage (UMat x,string s)
54
+ static void DisplayImage (Mat x,string s)
59
55
{
60
56
vector<Mat> sx;
61
57
split (x, sx);
62
58
vector<double > minVal (3 ), maxVal (3 );
63
- for (int i = 0 ; i < static_cast < int >( sx.size () ); i++)
59
+ for (size_t i = 0 ; i < sx.size (); i++)
64
60
{
65
61
minMaxLoc (sx[i], &minVal[i], &maxVal[i]);
66
62
}
@@ -78,32 +74,47 @@ static void DisplayImage(UMat x,string s)
78
74
*/
79
75
static void DericheFilter (int , void *)
80
76
{
81
- UMat dst;
77
+ Mat dst;
82
78
double d=alDerive/100.0 ,m=alMean/100.0 ;
83
- UMat rx= GradientDericheX (img,d,m);
84
- UMat ry= GradientDericheY (img,d,m);
79
+ Mat rx,ry;
80
+ GradientDericheX (img,rx,d,m);
81
+ GradientDericheY (img,ry,d,m);
85
82
DisplayImage (rx, " Gx" );
86
83
DisplayImage (ry, " Gy" );
87
84
add (rx.mul (rx),ry.mul (ry),dst);
88
85
sqrt (dst,dst);
89
- DisplayImage (dst, window_name );
86
+ DisplayImage (dst, winName );
90
87
}
91
88
92
89
93
90
int main (int argc, char * argv[])
94
91
{
92
+ cv::CommandLineParser parser (argc, argv, " {help h | | show help message}{@input | | input image}" );
93
+ if (parser.has (" help" ))
94
+ {
95
+ parser.printMessage ();
96
+ return 0 ;
97
+ }
98
+ string input_image = parser.get <string>(" @input" );
99
+ if (input_image.empty ())
100
+ {
101
+ parser.printMessage ();
102
+ parser.printErrors ();
103
+ return 0 ;
104
+ }
95
105
if (argc==2 )
96
- imread (argv[ 1 ]). copyTo (img );
106
+ img = imread (input_image );
97
107
if (img.empty ())
98
108
{
99
109
cout << " File not found or empty image\n " ;
110
+ return -1 ;
100
111
}
101
112
imshow (" Original" ,img);
102
- namedWindow ( window_name , WINDOW_AUTOSIZE );
113
+ namedWindow ( winName , WINDOW_AUTOSIZE );
103
114
104
115
// / Create a Trackbar for user to enter threshold
105
- createTrackbar ( " Derive:" ,window_name , &alDerive, 400 , DericheFilter );
106
- createTrackbar ( " Mean:" , window_name , &alMean, 400 , DericheFilter );
116
+ createTrackbar ( " Derive:" ,winName , &alDerive, 400 , DericheFilter );
117
+ createTrackbar ( " Mean:" , winName , &alMean, 400 , DericheFilter );
107
118
DericheFilter (0 ,NULL );
108
119
waitKey ();
109
120
return 0 ;
0 commit comments