From fac09b5f58c08fa198c40cc970735cb52c4ab80d Mon Sep 17 00:00:00 2001 From: vp153 Date: Mon, 15 Mar 2010 18:32:23 +0000 Subject: [PATCH] fixed some singular cases in findHomography (ticket #76) git-svn-id: https://code.ros.org/svn/opencv/trunk@2821 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08 --- opencv/src/cv/cvfundam.cpp | 5 ++++- opencv/src/cv/cvmodelest.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/opencv/src/cv/cvfundam.cpp b/opencv/src/cv/cvfundam.cpp index 016afc1d..5d3f6b67 100644 --- a/opencv/src/cv/cvfundam.cpp +++ b/opencv/src/cv/cvfundam.cpp @@ -109,6 +109,9 @@ int CvHomographyEstimator::runKernel( const CvMat* m1, const CvMat* m2, CvMat* H sM.y += fabs(M[i].y - cM.y); } + if( fabs(sm.x) < DBL_EPSILON || fabs(sm.y) < DBL_EPSILON || + fabs(sM.x) < DBL_EPSILON || fabs(sM.y) < DBL_EPSILON ) + return 0; sm.x = count/sm.x; sm.y = count/sm.y; sM.x = count/sM.x; sM.y = count/sM.y; @@ -247,7 +250,7 @@ cvFindHomography( const CvMat* objectPoints, const CvMat* imagePoints, if( !tempMask.empty() ) cvSet( tempMask, cvScalarAll(1.) ); - CvHomographyEstimator estimator( MIN(count, 5) ); + CvHomographyEstimator estimator( MIN(count, 4) ); if( count == 4 ) method = 0; if( method == CV_LMEDS ) diff --git a/opencv/src/cv/cvmodelest.cpp b/opencv/src/cv/cvmodelest.cpp index 18dd3292..801b23b1 100644 --- a/opencv/src/cv/cvmodelest.cpp +++ b/opencv/src/cv/cvmodelest.cpp @@ -343,7 +343,7 @@ bool CvModelEstimator2::checkSubset( const CvMat* m, int count ) { double dx2 = ptr[k].x - ptr[i].x; double dy2 = ptr[k].y - ptr[i].y; - if( fabs(dx2*dy1 - dy2*dx1) < FLT_EPSILON*(fabs(dx1) + fabs(dy1) + fabs(dx2) + fabs(dy2))) + if( fabs(dx2*dy1 - dy2*dx1) <= FLT_EPSILON*(fabs(dx1) + fabs(dy1) + fabs(dx2) + fabs(dy2))) break; } if( k < j ) -- 2.39.2