mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-22 16:08:41 +08:00
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
This commit is contained in:
@@ -11,7 +11,7 @@ using namespace cv::stereo;
|
||||
|
||||
enum { STEREO_BINARY_BM, STEREO_BINARY_SGM };
|
||||
static cv::CommandLineParser parse_argument_values(int argc, char **argv, string &left, string &right, int &kernel_size, int &number_of_disparities,
|
||||
int &aggregation_window, int &P1, int &P2, float &scale, int &algo, int &binary_descriptor_type);
|
||||
int &aggregation_window, int &P1, int &P2, float &scale, int &algo, int &binary_descriptor_type, int &success);
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
string left, right;
|
||||
@@ -19,6 +19,7 @@ int main(int argc, char** argv)
|
||||
float scale = 4;
|
||||
int algo = STEREO_BINARY_BM;
|
||||
int binary_descriptor_type = 0;
|
||||
int success;
|
||||
// here we extract the values that were added as arguments
|
||||
// we also test to see if they are provided correcly
|
||||
cv::CommandLineParser parser =
|
||||
@@ -28,50 +29,12 @@ int main(int argc, char** argv)
|
||||
aggregation_window,
|
||||
P1, P2,
|
||||
scale,
|
||||
algo, binary_descriptor_type);
|
||||
|
||||
if (!parser.check())
|
||||
algo, binary_descriptor_type,success);
|
||||
if (!parser.check() || !success)
|
||||
{
|
||||
parser.printMessage();
|
||||
return 1;
|
||||
}
|
||||
int fail = 0;
|
||||
//TEST if the provided parameters are correct
|
||||
if(binary_descriptor_type == CV_DENSE_CENSUS && kernel_size > 5)
|
||||
{
|
||||
cout << "For the dense census transform the maximum kernel size should be 5\n";
|
||||
fail = 1;
|
||||
}
|
||||
if((binary_descriptor_type == CV_MEAN_VARIATION || binary_descriptor_type == CV_MODIFIED_CENSUS_TRANSFORM || binary_descriptor_type == CV_STAR_KERNEL) && kernel_size != 9)
|
||||
{
|
||||
cout <<" For Mean variation and the modified census transform the kernel size should be equal to 9\n";
|
||||
fail = 1;
|
||||
}
|
||||
if((binary_descriptor_type == CV_CS_CENSUS || binary_descriptor_type == CV_MODIFIED_CS_CENSUS) && kernel_size > 7)
|
||||
{
|
||||
cout << " The kernel size should be smaller or equal to 7 for the CS census and modified center symetric census\n";
|
||||
fail = 1;
|
||||
}
|
||||
if(binary_descriptor_type == CV_SPARSE_CENSUS && kernel_size > 11)
|
||||
{
|
||||
cout << "The kernel size for the sparse census must be smaller or equal to 11\n";
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
if(number_of_disparities < 10)
|
||||
{
|
||||
cout << "Number of disparities should be greater than 10\n";
|
||||
fail = 1;
|
||||
}
|
||||
if(P2 / P1 < 2)
|
||||
{
|
||||
cout << "You should probabilly choose a greater P2 penalty\n";
|
||||
fail = 1;
|
||||
}
|
||||
if(fail == 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
// verify if the user inputs the correct number of parameters
|
||||
Mat image1, image2;
|
||||
// we read a pair of images from the disk
|
||||
@@ -85,7 +48,6 @@ int main(int argc, char** argv)
|
||||
parser.printMessage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// we display the parsed parameters
|
||||
const char *b[7] = { "CV_DENSE_CENSUS", "CV_SPARSE_CENSUS", "CV_CS_CENSUS", "CV_MODIFIED_CS_CENSUS",
|
||||
"CV_MODIFIED_CENSUS_TRANSFORM", "CV_MEAN_VARIATION", "CV_STAR_KERNEL" };
|
||||
@@ -151,21 +113,20 @@ int main(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
static cv::CommandLineParser parse_argument_values(int argc, char **argv, string &left, string &right, int &kernel_size, int &number_of_disparities,
|
||||
int &aggregation_window, int &P1, int &P2, float &scale, int &algo, int &binary_descriptor_type)
|
||||
int &aggregation_window, int &P1, int &P2, float &scale, int &algo, int &binary_descriptor_type, int &success)
|
||||
{
|
||||
static const char* keys =
|
||||
"{ @left | | }"
|
||||
"{ @right | | }"
|
||||
"{ k kernel_size | 9 | }"
|
||||
"{ d disparity | 128 | }"
|
||||
"{ w aggregation_window | 9 | }"
|
||||
"{ P1 | 100 | }"
|
||||
"{ P2 | 1000 | }"
|
||||
"{ 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}"
|
||||
"{ s scale | 1.01593 | }"
|
||||
"{ k kernel_size | 9 | }"
|
||||
"{ d disparity | 128 | }"
|
||||
"{ w aggregation_window | 9 | }"
|
||||
"{ P1 | 100 | }"
|
||||
"{ P2 | 1000 | }"
|
||||
"{ 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}"
|
||||
"{ s scale | 1.01593 | }"
|
||||
"{ a algorithm | sgm | }"
|
||||
;
|
||||
|
||||
cv::CommandLineParser parser( argc, argv, keys );
|
||||
|
||||
left = parser.get<string>(0);
|
||||
@@ -181,5 +142,55 @@ static cv::CommandLineParser parse_argument_values(int argc, char **argv, string
|
||||
|
||||
parser.about("\nDemo stereo matching converting L and R images into disparity images using BM and SGBM\n");
|
||||
|
||||
success = 1;
|
||||
//TEST if the provided parameters are correct
|
||||
if(binary_descriptor_type == CV_DENSE_CENSUS && kernel_size > 5)
|
||||
{
|
||||
cout << "For the dense census transform the maximum kernel size should be 5\n";
|
||||
success = 0;
|
||||
}
|
||||
if((binary_descriptor_type == CV_MEAN_VARIATION || binary_descriptor_type == CV_MODIFIED_CENSUS_TRANSFORM || binary_descriptor_type == CV_STAR_KERNEL) && kernel_size != 9)
|
||||
{
|
||||
cout <<" For Mean variation and the modified census transform the kernel size should be equal to 9\n";
|
||||
success = 0;
|
||||
}
|
||||
if((binary_descriptor_type == CV_CS_CENSUS || binary_descriptor_type == CV_MODIFIED_CS_CENSUS) && kernel_size > 7)
|
||||
{
|
||||
cout << " The kernel size should be smaller or equal to 7 for the CS census and modified center symetric census\n";
|
||||
success = 0;
|
||||
}
|
||||
if(binary_descriptor_type == CV_SPARSE_CENSUS && kernel_size > 11)
|
||||
{
|
||||
cout << "The kernel size for the sparse census must be smaller or equal to 11\n";
|
||||
success = 0;
|
||||
}
|
||||
if(number_of_disparities < 10)
|
||||
{
|
||||
cout << "Number of disparities should be greater than 10\n";
|
||||
success = 0;
|
||||
}
|
||||
if(aggregation_window < 3)
|
||||
{
|
||||
cout << "Aggregation window should be > 3";
|
||||
success = 0;
|
||||
}
|
||||
if(scale < 1)
|
||||
{
|
||||
cout << "The scale should be a positive number \n";
|
||||
success = 0;
|
||||
}
|
||||
if(P1 != 0)
|
||||
{
|
||||
if(P2 / P1 < 2)
|
||||
{
|
||||
cout << "You should probably choose a greater P2 penalty\n";
|
||||
success = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << " Penalties should be greater than 0\n";
|
||||
success = 0;
|
||||
}
|
||||
return parser;
|
||||
}
|
||||
|
Reference in New Issue
Block a user