Skip to content

Commit c83e49a

Browse files
committed
modify sample by adding the checks in the parse function
some extra conditions added to the sample changed scale fixed some issues regarding the matching and the sample modified expression for hamming lut condition in confidence check changed the name : bm to sgm for sample
1 parent e7ab49e commit c83e49a

File tree

2 files changed

+68
-54
lines changed

2 files changed

+68
-54
lines changed

modules/stereo/samples/sample.cpp

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ using namespace cv::stereo;
1111

1212
enum { STEREO_BINARY_BM, STEREO_BINARY_SGM };
1313
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);
1515
int main(int argc, char** argv)
1616
{
1717
string left, right;
1818
int kernel_size = 0, number_of_disparities = 0, aggregation_window = 0, P1 = 0, P2 = 0;
1919
float scale = 4;
2020
int algo = STEREO_BINARY_BM;
2121
int binary_descriptor_type = 0;
22+
int success;
2223
// here we extract the values that were added as arguments
2324
// we also test to see if they are provided correcly
2425
cv::CommandLineParser parser =
@@ -28,50 +29,12 @@ int main(int argc, char** argv)
2829
aggregation_window,
2930
P1, P2,
3031
scale,
31-
algo, binary_descriptor_type);
32-
33-
if (!parser.check())
32+
algo, binary_descriptor_type,success);
33+
if (!parser.check() || !success)
3434
{
3535
parser.printMessage();
3636
return 1;
3737
}
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-
}
7538
// verify if the user inputs the correct number of parameters
7639
Mat image1, image2;
7740
// we read a pair of images from the disk
@@ -85,7 +48,6 @@ int main(int argc, char** argv)
8548
parser.printMessage();
8649
return 1;
8750
}
88-
8951
// we display the parsed parameters
9052
const char *b[7] = { "CV_DENSE_CENSUS", "CV_SPARSE_CENSUS", "CV_CS_CENSUS", "CV_MODIFIED_CS_CENSUS",
9153
"CV_MODIFIED_CENSUS_TRANSFORM", "CV_MEAN_VARIATION", "CV_STAR_KERNEL" };
@@ -151,21 +113,20 @@ int main(int argc, char** argv)
151113
return 0;
152114
}
153115
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)
155117
{
156118
static const char* keys =
157119
"{ @left | | }"
158120
"{ @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 | }"
166128
"{ a algorithm | sgm | }"
167129
;
168-
169130
cv::CommandLineParser parser( argc, argv, keys );
170131

171132
left = parser.get<string>(0);
@@ -181,5 +142,55 @@ static cv::CommandLineParser parse_argument_values(int argc, char **argv, string
181142

182143
parser.about("\nDemo stereo matching converting L and R images into disparity images using BM and SGBM\n");
183144

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+
}
184195
return parser;
185196
}

modules/stereo/src/matching.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ namespace cv
9595
mini3 = c[(iw + i * search_region) * widthDisp2 + i];
9696
}
9797
}
98-
if (mini3 / mini <= confidence)
99-
return index;
98+
if(mini != 0)
99+
{
100+
if (mini3 / mini <= confidence)
101+
return index;
102+
}
100103
return -1;
101104
}
102105
//!Interpolate in order to obtain better results
@@ -171,7 +174,7 @@ namespace cv
171174
#if CV_SSE4_1
172175
c[(iwj)* (v + 1) + d] = (short)_mm_popcnt_u32(xorul);
173176
#else
174-
c[(iwj)* (v + 1) + d] = (short)(hammLut[xorul & MASK] + hammLut[xorul >> 16]);
177+
c[(iwj)* (v + 1) + d] = (short)(hammLut[xorul & MASK] + hammLut[(xorul >> 16) & MASK]);
175178
#endif
176179
}
177180
}

0 commit comments

Comments
 (0)