From ad8258f8721b01a6210c39e5c9d6620cc98b4271 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 24 Apr 2012 13:08:56 +0000 Subject: [PATCH] =?UTF-8?q?avoid=20infinite=20loop=20in=20CvLevMarq=20(tha?= =?UTF-8?q?nks=20to=20Jo=C3=A3o=20Lima=20for=20the=20patch;=20ticket=20#18?= =?UTF-8?q?39)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/calib3d/src/calibration.cpp | 32 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index 35b318ebf6..27be3ab613 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -166,13 +166,15 @@ bool CvLevMarq::update( const CvMat*& _param, CvMat*& matJ, CvMat*& _err ) errNorm = cvNorm( err, 0, CV_L2 ); if( errNorm > prevErrNorm ) { - lambdaLg10++; - step(); - _param = param; - cvZero( err ); - _err = err; - state = CHECK_ERR; - return true; + if( ++lambdaLg10 <= 16 ) + { + step(); + _param = param; + cvZero( err ); + _err = err; + state = CHECK_ERR; + return true; + } } lambdaLg10 = MAX(lambdaLg10-1, -16); @@ -233,13 +235,15 @@ bool CvLevMarq::updateAlt( const CvMat*& _param, CvMat*& _JtJ, CvMat*& _JtErr, d assert( state == CHECK_ERR ); if( errNorm > prevErrNorm ) { - lambdaLg10++; - step(); - _param = param; - errNorm = 0; - _errNorm = &errNorm; - state = CHECK_ERR; - return true; + if( ++lambdaLg10 <= 16 ) + { + step(); + _param = param; + errNorm = 0; + _errNorm = &errNorm; + state = CHECK_ERR; + return true; + } } lambdaLg10 = MAX(lambdaLg10-1, -16);