From b5ddaae427a1dbcabc72a99c6345eb87fbcd1658 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Thu, 10 Dec 2015 23:26:37 +0100 Subject: [PATCH] calib3d: add CALIB_USE_LU to use LU decomposition in solver --- modules/calib3d/include/opencv2/calib3d.hpp | 3 ++- modules/calib3d/src/calibration.cpp | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/calib3d/include/opencv2/calib3d.hpp b/modules/calib3d/include/opencv2/calib3d.hpp index 2f36afd2fa..a472bab115 100644 --- a/modules/calib3d/include/opencv2/calib3d.hpp +++ b/modules/calib3d/include/opencv2/calib3d.hpp @@ -225,7 +225,8 @@ enum { CALIB_USE_INTRINSIC_GUESS = 0x00001, CALIB_FIX_INTRINSIC = 0x00100, CALIB_SAME_FOCAL_LENGTH = 0x00200, // for stereo rectification - CALIB_ZERO_DISPARITY = 0x00400 + CALIB_ZERO_DISPARITY = 0x00400, + CALIB_USE_LU = (1 << 17), //!< use LU instead of SVD decomposition for solving. much faster but potentially less precise }; //! the algorithm for finding fundamental matrix diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index fc0a267be1..5d570ba97d 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -1232,7 +1232,6 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints, CvMat* rvecs, CvMat* tvecs, int flags, CvTermCriteria termCrit ) { const int NINTRINSIC = 16; - CvLevMarq solver; double reprojErr = 0; Matx33d A; @@ -1388,7 +1387,11 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints, cvInitIntrinsicParams2D( &_matM, &m, npoints, imageSize, &matA, aspectRatio ); } - solver.init( nparams, 0, termCrit ); + CvLevMarq solver( nparams, 0, termCrit ); + + if(flags & CALIB_USE_LU) { + solver.solveMethod = DECOMP_LU; + } { double* param = solver.param->data.db; @@ -1635,7 +1638,6 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1 { const int NINTRINSIC = 16; Ptr npoints, err, J_LR, Je, Ji, imagePoints[2], objectPoints, RT0; - CvLevMarq solver; double reprojErr = 0; double A[2][9], dk[2][12]={{0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0}}, rlr[9]; @@ -1737,7 +1739,12 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1 // storage for initial [om(R){i}|t{i}] (in order to compute the median for each component) RT0.reset(cvCreateMat( 6, nimages, CV_64F )); - solver.init( nparams, 0, termCrit ); + CvLevMarq solver( nparams, 0, termCrit ); + + if(flags & CALIB_USE_LU) { + solver.solveMethod = DECOMP_LU; + } + if( recomputeIntrinsics ) { uchar* imask = solver.mask->data.ptr + nparams - NINTRINSIC*2; -- GitLab