From c57799a877410dfb13d39883d1971ac48baea276 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Wed, 3 Aug 2011 14:04:14 +0000 Subject: [PATCH] fixed 8-point case in findFundamentalMat (ticket #1262). findFundamentalMat needs to be rewritten actually (as well as findHomography) --- modules/calib3d/src/fundam.cpp | 8 ++++---- modules/core/src/lapack.cpp | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/modules/calib3d/src/fundam.cpp b/modules/calib3d/src/fundam.cpp index b289db6..b7cffa0 100644 --- a/modules/calib3d/src/fundam.cpp +++ b/modules/calib3d/src/fundam.cpp @@ -499,7 +499,7 @@ int CvFMEstimator::run8Point( const CvMat* _m1, const CvMat* _m2, CvMat* _fmatri a[j*9+k] += r[j]*r[k]; } - cvSVD( &A, &W, 0, &V, CV_SVD_MODIFY_A + CV_SVD_V_T ); + cvEigenVV(&A, &V, &W); for( i = 0; i < 8; i++ ) { @@ -616,7 +616,7 @@ CV_IMPL int cvFindFundamentalMat( const CvMat* points1, const CvMat* points2, (mask->rows == 1 || mask->cols == 1) && mask->rows*mask->cols == count ); } - if( mask || count > 8 ) + if( mask || count >= 8 ) tempMask = cvCreateMat( 1, count, CV_8U ); if( !tempMask.empty() ) cvSet( tempMask, cvScalarAll(1.) ); @@ -624,9 +624,9 @@ CV_IMPL int cvFindFundamentalMat( const CvMat* points1, const CvMat* points2, CvFMEstimator estimator(7); if( count == 7 ) result = estimator.run7Point(m1, m2, &_F9x3); - else if( count == 8 || method == CV_FM_8POINT ) + else if( method == CV_FM_8POINT ) result = estimator.run8Point(m1, m2, &_F3x3); - else if( count >= 8 ) + else { if( param1 <= 0 ) param1 = 3; diff --git a/modules/core/src/lapack.cpp b/modules/core/src/lapack.cpp index 18656fd..c88125e 100644 --- a/modules/core/src/lapack.cpp +++ b/modules/core/src/lapack.cpp @@ -1637,14 +1637,31 @@ CV_IMPL void cvEigenVV( CvArr* srcarr, CvArr* evectsarr, CvArr* evalsarr, double, int lowindex, int highindex) { - cv::Mat src = cv::cvarrToMat(srcarr), evals = cv::cvarrToMat(evalsarr); + cv::Mat src = cv::cvarrToMat(srcarr), evals0 = cv::cvarrToMat(evalsarr), evals = evals0; if( evectsarr ) { - cv::Mat evects = cv::cvarrToMat(evectsarr); + cv::Mat evects0 = cv::cvarrToMat(evectsarr), evects = evects0; eigen(src, evals, evects, lowindex, highindex); + if( evects0.data != evects.data ) + { + uchar* p = evects0.data; + evects.convertTo(evects0, evects0.type()); + CV_Assert( p == evects0.data ); + } } else eigen(src, evals, lowindex, highindex); + if( evals0.data != evals.data ) + { + uchar* p = evals0.data; + if( evals0.size() == evals.size() ) + evals.convertTo(evals0, evals0.type()); + else if( evals0.type() == evals.type() ) + cv::transpose(evals, evals0); + else + cv::Mat(evals.t()).convertTo(evals0, evals0.type()); + CV_Assert( p == evals0.data ); + } } -- 2.7.4