From aed276e67d16076d366f997b098829bad8eaeee7 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Wed, 28 Mar 2012 13:37:14 +0000 Subject: [PATCH] fixed cvComputeCorrespondEpilines to handle <5 points (ticket #1635) --- modules/calib3d/src/fundam.cpp | 24 ++++++++++++++++++------ modules/calib3d/test/test_fundam.cpp | 15 ++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/modules/calib3d/src/fundam.cpp b/modules/calib3d/src/fundam.cpp index 67ac2c1..7b6ce7b 100644 --- a/modules/calib3d/src/fundam.cpp +++ b/modules/calib3d/src/fundam.cpp @@ -680,7 +680,13 @@ CV_IMPL void cvComputeCorrespondEpilines( const CvMat* points, int pointImageID, if( (depth != CV_32F && depth != CV_64F) || (cn != 1 && cn != 2 && cn != 3) ) CV_Error( CV_StsUnsupportedFormat, "The format of point matrix is unsupported" ); - if( points->rows > points->cols ) + if( cn > 1 ) + { + dims = cn; + CV_Assert( points->rows == 1 || points->cols == 1 ); + count = points->rows * points->cols; + } + else if( points->rows > points->cols ) { dims = cn*points->cols; count = points->rows; @@ -689,7 +695,7 @@ CV_IMPL void cvComputeCorrespondEpilines( const CvMat* points, int pointImageID, { if( (points->rows > 1 && cn > 1) || (points->rows == 1 && cn == 1) ) CV_Error( CV_StsBadSize, "The point matrix does not have a proper layout (2xn, 3xn, nx2 or nx3)" ); - dims = cn * points->rows; + dims = points->rows; count = points->cols; } @@ -713,7 +719,13 @@ CV_IMPL void cvComputeCorrespondEpilines( const CvMat* points, int pointImageID, if( (abc_depth != CV_32F && abc_depth != CV_64F) || (abc_cn != 1 && abc_cn != 3) ) CV_Error( CV_StsUnsupportedFormat, "The format of the matrix of lines is unsupported" ); - if( lines->rows > lines->cols ) + if( abc_cn > 1 ) + { + abc_dims = abc_cn; + CV_Assert( lines->rows == 1 || lines->cols == 1 ); + abc_count = lines->rows * lines->cols; + } + else if( lines->rows > lines->cols ) { abc_dims = abc_cn*lines->cols; abc_count = lines->rows; @@ -722,7 +734,7 @@ CV_IMPL void cvComputeCorrespondEpilines( const CvMat* points, int pointImageID, { if( (lines->rows > 1 && abc_cn > 1) || (lines->rows == 1 && abc_cn == 1) ) CV_Error( CV_StsBadSize, "The lines matrix does not have a proper layout (3xn or nx3)" ); - abc_dims = abc_cn * lines->rows; + abc_dims = lines->rows; abc_count = lines->cols; } @@ -735,7 +747,7 @@ CV_IMPL void cvComputeCorrespondEpilines( const CvMat* points, int pointImageID, elem_size = CV_ELEM_SIZE(depth); abc_elem_size = CV_ELEM_SIZE(abc_depth); - if( points->rows == dims ) + if( cn == 1 && points->rows == dims ) { plane_stride = points->step; stride = elem_size; @@ -746,7 +758,7 @@ CV_IMPL void cvComputeCorrespondEpilines( const CvMat* points, int pointImageID, stride = points->rows == 1 ? dims*elem_size : points->step; } - if( lines->rows == 3 ) + if( abc_cn == 1 && lines->rows == 3 ) { abc_plane_stride = lines->step; abc_stride = abc_elem_size; diff --git a/modules/calib3d/test/test_fundam.cpp b/modules/calib3d/test/test_fundam.cpp index 0ee21f7..ed1bb59 100644 --- a/modules/calib3d/test/test_fundam.cpp +++ b/modules/calib3d/test/test_fundam.cpp @@ -1246,23 +1246,24 @@ void CV_ComputeEpilinesTest::get_test_array_types_and_sizes( int /*test_case_idx int fm_depth = cvtest::randInt(rng) % 2 == 0 ? CV_32F : CV_64F; int pt_depth = cvtest::randInt(rng) % 2 == 0 ? CV_32F : CV_64F; int ln_depth = cvtest::randInt(rng) % 2 == 0 ? CV_32F : CV_64F; - double pt_count_exp = cvtest::randReal(rng)*6 + 1; + double pt_count_exp = cvtest::randReal(rng)*6; which_image = 1 + (cvtest::randInt(rng) % 2); pt_count = cvRound(exp(pt_count_exp)); - pt_count = MAX( pt_count, 5 ); + pt_count = MAX( pt_count, 1 ); + bool few_points = pt_count < 5; dims = 2 + (cvtest::randInt(rng) % 2); types[INPUT][0] = CV_MAKETYPE(pt_depth, 1); - if( cvtest::randInt(rng) % 2 ) + if( cvtest::randInt(rng) % 2 && !few_points ) sizes[INPUT][0] = cvSize(pt_count, dims); else { sizes[INPUT][0] = cvSize(dims, pt_count); - if( cvtest::randInt(rng) % 2 ) + if( cvtest::randInt(rng) % 2 || few_points ) { types[INPUT][0] = CV_MAKETYPE(pt_depth, dims); if( cvtest::randInt(rng) % 2 ) @@ -1277,12 +1278,12 @@ void CV_ComputeEpilinesTest::get_test_array_types_and_sizes( int /*test_case_idx types[OUTPUT][0] = CV_MAKETYPE(ln_depth, 1); - if( cvtest::randInt(rng) % 2 ) + if( cvtest::randInt(rng) % 2 && !few_points ) sizes[OUTPUT][0] = cvSize(pt_count, 3); else { sizes[OUTPUT][0] = cvSize(3, pt_count); - if( cvtest::randInt(rng) % 2 ) + if( cvtest::randInt(rng) % 2 || few_points ) { types[OUTPUT][0] = CV_MAKETYPE(ln_depth, 3); if( cvtest::randInt(rng) % 2 ) @@ -1354,10 +1355,10 @@ void CV_ComputeEpilinesTest::prepare_to_validation( int /*test_case_idx*/ ) test_convertHomogeneous( lines, test_mat[REF_OUTPUT][0] ); } - TEST(Calib3d_Rodrigues, accuracy) { CV_RodriguesTest test; test.safe_run(); } TEST(Calib3d_FindFundamentalMat, accuracy) { CV_FundamentalMatTest test; test.safe_run(); } TEST(Calib3d_ConvertHomogeneoous, accuracy) { CV_ConvertHomogeneousTest test; test.safe_run(); } TEST(Calib3d_ComputeEpilines, accuracy) { CV_ComputeEpilinesTest test; test.safe_run(); } + /* End of file. */ -- 2.7.4