From f34a0a874a029a6201df0acbf46eeeaab8686e4d Mon Sep 17 00:00:00 2001 From: tobycollins Date: Tue, 9 Jan 2018 13:54:36 +0100 Subject: [PATCH] Merge pull request #10522 from tobycollins:issue10519 --- modules/calib3d/src/calibration.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index 8a93c90ed3..5cf1fdc070 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -1009,6 +1009,8 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints, CV_Assert( (CV_MAT_DEPTH(tvec->type) == CV_64F || CV_MAT_DEPTH(tvec->type) == CV_32F) && (tvec->rows == 1 || tvec->cols == 1) && tvec->rows*tvec->cols*CV_MAT_CN(tvec->type) == 3 ); + CV_Assert((count >= 4) || (count == 3 && useExtrinsicGuess)); // it is unsafe to call LM optimisation without an extrinsic guess in the case of 3 points. This is because there is no guarantee that it will converge on the correct solution. + _mn.reset(cvCreateMat( 1, count, CV_64FC2 )); _Mxy.reset(cvCreateMat( 1, count, CV_64FC2 )); @@ -1033,7 +1035,7 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints, cvSVD( &_MM, &matW, 0, &matV, CV_SVD_MODIFY_A + CV_SVD_V_T ); // initialize extrinsic parameters - if( W[2]/W[1] < 1e-3 || count < 4 ) + if( W[2]/W[1] < 1e-3) { // a planar structure case (all M's lie in the same plane) double tt[3], h[9], h1_norm, h2_norm;