diff --git a/modules/calib3d/test/test_fundam.cpp b/modules/calib3d/test/test_fundam.cpp index 5f8d30de40..5b77dc308a 100644 --- a/modules/calib3d/test/test_fundam.cpp +++ b/modules/calib3d/test/test_fundam.cpp @@ -1709,4 +1709,21 @@ TEST(Calib3d_ConvertHomogeneoous, accuracy) { CV_ConvertHomogeneousTest test; te TEST(Calib3d_ComputeEpilines, accuracy) { CV_ComputeEpilinesTest test; test.safe_run(); } TEST(Calib3d_FindEssentialMat, accuracy) { CV_EssentialMatTest test; test.safe_run(); } +TEST(Calib3d_FindFundamentalMat, correctMatches) +{ + double fdata[] = {0, 0, 0, 0, 0, -1, 0, 1, 0}; + double p1data[] = {200, 0, 1}; + double p2data[] = {170, 0, 1}; + + Mat F(3, 3, CV_64F, fdata); + Mat p1(1, 1, CV_64FC2, p1data); + Mat p2(1, 1, CV_64FC2, p2data); + Mat np1, np2; + + correctMatches(F, p1, p2, np1, np2); + + cout << np1 << endl; + cout << np2 << endl; +} + /* End of file. */ diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index b8e4b1a2ed..97f36299d8 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -2047,7 +2047,7 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters ) CV_Assert( CV_MAT_DEPTH(ctype) >= CV_32F && CV_MAT_CN(ctype) <= 2 ); CV_Assert( coeffs0.rows == 1 || coeffs0.cols == 1 ); - int n = coeffs0.cols + coeffs0.rows - 2; + int n0 = coeffs0.cols + coeffs0.rows - 2, n = n0; _roots0.create(n, 1, CV_MAKETYPE(cdepth, 2), -1, true, _OutputArray::DEPTH_MASK_FLT); Mat roots0 = _roots0.getMat(); @@ -2063,6 +2063,12 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters ) coeffs[i] = C(rcoeffs[i], 0); } + for( ; n > 1; n-- ) + { + if( std::abs(coeffs[n].re) + std::abs(coeffs[n].im) > DBL_EPSILON ) + break; + } + C p(1, 0), r(1, 1); for( i = 0; i < n; i++ ) @@ -2100,6 +2106,9 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters ) roots[i].im = 0; } + for( ; n < n0; n++ ) + roots[n+1] = roots[n]; + Mat(roots0.size(), CV_64FC2, roots).convertTo(roots0, roots0.type()); return maxDiff; }