@@ -11,14 +11,15 @@ using namespace cv::stereo;
11
11
12
12
enum { STEREO_BINARY_BM, STEREO_BINARY_SGM };
13
13
static cv::CommandLineParser parse_argument_values (int argc, char **argv, string &left, string &right, int &kernel_size, int &number_of_disparities,
14
- int &aggregation_window, int &P1, int &P2, float &scale, int &algo, int &binary_descriptor_type);
14
+ int &aggregation_window, int &P1, int &P2, float &scale, int &algo, int &binary_descriptor_type, int &success );
15
15
int main (int argc, char ** argv)
16
16
{
17
17
string left, right;
18
18
int kernel_size = 0 , number_of_disparities = 0 , aggregation_window = 0 , P1 = 0 , P2 = 0 ;
19
19
float scale = 4 ;
20
20
int algo = STEREO_BINARY_BM;
21
21
int binary_descriptor_type = 0 ;
22
+ int success;
22
23
// here we extract the values that were added as arguments
23
24
// we also test to see if they are provided correcly
24
25
cv::CommandLineParser parser =
@@ -28,50 +29,12 @@ int main(int argc, char** argv)
28
29
aggregation_window,
29
30
P1, P2,
30
31
scale,
31
- algo, binary_descriptor_type);
32
-
33
- if (!parser.check ())
32
+ algo, binary_descriptor_type,success);
33
+ if (!parser.check () || !success)
34
34
{
35
35
parser.printMessage ();
36
36
return 1 ;
37
37
}
38
- int fail = 0 ;
39
- // TEST if the provided parameters are correct
40
- if (binary_descriptor_type == CV_DENSE_CENSUS && kernel_size > 5 )
41
- {
42
- cout << " For the dense census transform the maximum kernel size should be 5\n " ;
43
- fail = 1 ;
44
- }
45
- if ((binary_descriptor_type == CV_MEAN_VARIATION || binary_descriptor_type == CV_MODIFIED_CENSUS_TRANSFORM || binary_descriptor_type == CV_STAR_KERNEL) && kernel_size != 9 )
46
- {
47
- cout <<" For Mean variation and the modified census transform the kernel size should be equal to 9\n " ;
48
- fail = 1 ;
49
- }
50
- if ((binary_descriptor_type == CV_CS_CENSUS || binary_descriptor_type == CV_MODIFIED_CS_CENSUS) && kernel_size > 7 )
51
- {
52
- cout << " The kernel size should be smaller or equal to 7 for the CS census and modified center symetric census\n " ;
53
- fail = 1 ;
54
- }
55
- if (binary_descriptor_type == CV_SPARSE_CENSUS && kernel_size > 11 )
56
- {
57
- cout << " The kernel size for the sparse census must be smaller or equal to 11\n " ;
58
- fail = 1 ;
59
- }
60
-
61
- if (number_of_disparities < 10 )
62
- {
63
- cout << " Number of disparities should be greater than 10\n " ;
64
- fail = 1 ;
65
- }
66
- if (P2 / P1 < 2 )
67
- {
68
- cout << " You should probabilly choose a greater P2 penalty\n " ;
69
- fail = 1 ;
70
- }
71
- if (fail == 1 )
72
- {
73
- return 1 ;
74
- }
75
38
// verify if the user inputs the correct number of parameters
76
39
Mat image1, image2;
77
40
// we read a pair of images from the disk
@@ -85,7 +48,6 @@ int main(int argc, char** argv)
85
48
parser.printMessage ();
86
49
return 1 ;
87
50
}
88
-
89
51
// we display the parsed parameters
90
52
const char *b[7 ] = { " CV_DENSE_CENSUS" , " CV_SPARSE_CENSUS" , " CV_CS_CENSUS" , " CV_MODIFIED_CS_CENSUS" ,
91
53
" CV_MODIFIED_CENSUS_TRANSFORM" , " CV_MEAN_VARIATION" , " CV_STAR_KERNEL" };
@@ -151,21 +113,20 @@ int main(int argc, char** argv)
151
113
return 0 ;
152
114
}
153
115
static cv::CommandLineParser parse_argument_values (int argc, char **argv, string &left, string &right, int &kernel_size, int &number_of_disparities,
154
- int &aggregation_window, int &P1, int &P2, float &scale, int &algo, int &binary_descriptor_type)
116
+ int &aggregation_window, int &P1, int &P2, float &scale, int &algo, int &binary_descriptor_type, int &success )
155
117
{
156
118
static const char * keys =
157
119
" { @left | | }"
158
120
" { @right | | }"
159
- " { k kernel_size | 9 | }"
160
- " { d disparity | 128 | }"
161
- " { w aggregation_window | 9 | }"
162
- " { P1 | 100 | }"
163
- " { P2 | 1000 | }"
164
- " { b binary_descriptor | 4 | Index of the descriptor type:\n 0 - CV_DENSE_CENSUS,\n 1 - CV_SPARSE_CENSUS,\n 2 - CV_CS_CENSUS,\n 3 - CV_MODIFIED_CS_CENSUS,\n 4 - CV_MODIFIED_CENSUS_TRANSFORM,\n 5 - CV_MEAN_VARIATION,\n 6 - CV_STAR_KERNEL}"
165
- " { s scale | 1.01593 | }"
121
+ " { k kernel_size | 9 | }"
122
+ " { d disparity | 128 | }"
123
+ " { w aggregation_window | 9 | }"
124
+ " { P1 | 100 | }"
125
+ " { P2 | 1000 | }"
126
+ " { b binary_descriptor | 4 | Index of the descriptor type:\n 0 - CV_DENSE_CENSUS,\n 1 - CV_SPARSE_CENSUS,\n 2 - CV_CS_CENSUS,\n 3 - CV_MODIFIED_CS_CENSUS,\n 4 - CV_MODIFIED_CENSUS_TRANSFORM,\n 5 - CV_MEAN_VARIATION,\n 6 - CV_STAR_KERNEL}"
127
+ " { s scale | 1.01593 | }"
166
128
" { a algorithm | sgm | }"
167
129
;
168
-
169
130
cv::CommandLineParser parser ( argc, argv, keys );
170
131
171
132
left = parser.get <string>(0 );
@@ -181,5 +142,55 @@ static cv::CommandLineParser parse_argument_values(int argc, char **argv, string
181
142
182
143
parser.about (" \n Demo stereo matching converting L and R images into disparity images using BM and SGBM\n " );
183
144
145
+ success = 1 ;
146
+ // TEST if the provided parameters are correct
147
+ if (binary_descriptor_type == CV_DENSE_CENSUS && kernel_size > 5 )
148
+ {
149
+ cout << " For the dense census transform the maximum kernel size should be 5\n " ;
150
+ success = 0 ;
151
+ }
152
+ if ((binary_descriptor_type == CV_MEAN_VARIATION || binary_descriptor_type == CV_MODIFIED_CENSUS_TRANSFORM || binary_descriptor_type == CV_STAR_KERNEL) && kernel_size != 9 )
153
+ {
154
+ cout <<" For Mean variation and the modified census transform the kernel size should be equal to 9\n " ;
155
+ success = 0 ;
156
+ }
157
+ if ((binary_descriptor_type == CV_CS_CENSUS || binary_descriptor_type == CV_MODIFIED_CS_CENSUS) && kernel_size > 7 )
158
+ {
159
+ cout << " The kernel size should be smaller or equal to 7 for the CS census and modified center symetric census\n " ;
160
+ success = 0 ;
161
+ }
162
+ if (binary_descriptor_type == CV_SPARSE_CENSUS && kernel_size > 11 )
163
+ {
164
+ cout << " The kernel size for the sparse census must be smaller or equal to 11\n " ;
165
+ success = 0 ;
166
+ }
167
+ if (number_of_disparities < 10 )
168
+ {
169
+ cout << " Number of disparities should be greater than 10\n " ;
170
+ success = 0 ;
171
+ }
172
+ if (aggregation_window < 3 )
173
+ {
174
+ cout << " Aggregation window should be > 3" ;
175
+ success = 0 ;
176
+ }
177
+ if (scale < 1 )
178
+ {
179
+ cout << " The scale should be a positive number \n " ;
180
+ success = 0 ;
181
+ }
182
+ if (P1 != 0 )
183
+ {
184
+ if (P2 / P1 < 2 )
185
+ {
186
+ cout << " You should probably choose a greater P2 penalty\n " ;
187
+ success = 0 ;
188
+ }
189
+ }
190
+ else
191
+ {
192
+ cout << " Penalties should be greater than 0\n " ;
193
+ success = 0 ;
194
+ }
184
195
return parser;
185
196
}
0 commit comments