mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 19:50:38 +08:00
Merge pull request #13910 from x3lif:Issue_13908
* Fix Issue 13908 Allocate the matrix _Jo only when the solver needs it (ie when solver.state == CvLevMarq::CALC_J) * Fix calib3D unit test Fix _Jo allocation when stddev is not empty * Removing trailing whitespaces * scope _dp* variables * fix whitespaces
This commit is contained in:
parent
7444f0c651
commit
19cf511895
@ -1520,10 +1520,6 @@ static double cvCalibrateCamera2Internal( const CvMat* objectPoints,
|
||||
nparams = NINTRINSIC + nimages*6;
|
||||
if( releaseObject )
|
||||
nparams += maxPoints * 3;
|
||||
Mat _Ji( maxPoints*2, NINTRINSIC, CV_64FC1, Scalar(0));
|
||||
Mat _Je( maxPoints*2, 6, CV_64FC1 );
|
||||
Mat _Jo( maxPoints*2, maxPoints*3, CV_64FC1, Scalar(0) );
|
||||
Mat _err( maxPoints*2, 1, CV_64FC1 );
|
||||
|
||||
_k = cvMat( distCoeffs->rows, distCoeffs->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(distCoeffs->type)), k);
|
||||
if( distCoeffs->rows*distCoeffs->cols*CV_MAT_CN(distCoeffs->type) < 8 )
|
||||
@ -1587,6 +1583,13 @@ static double cvCalibrateCamera2Internal( const CvMat* objectPoints,
|
||||
|
||||
CvLevMarq solver( nparams, 0, termCrit );
|
||||
|
||||
Mat _Ji( maxPoints*2, NINTRINSIC, CV_64FC1, Scalar(0));
|
||||
Mat _Je( maxPoints*2, 6, CV_64FC1 );
|
||||
Mat _err( maxPoints*2, 1, CV_64FC1 );
|
||||
|
||||
const bool allocJo = (solver.state == CvLevMarq::CALC_J) || stdDevs;
|
||||
Mat _Jo = allocJo ? Mat( maxPoints*2, maxPoints*3, CV_64FC1, Scalar(0) ) : Mat();
|
||||
|
||||
if(flags & CALIB_USE_LU) {
|
||||
solver.solveMethod = DECOMP_LU;
|
||||
}
|
||||
@ -1720,20 +1723,22 @@ static double cvCalibrateCamera2Internal( const CvMat* objectPoints,
|
||||
|
||||
_Je.resize(ni*2); _Ji.resize(ni*2); _err.resize(ni*2);
|
||||
_Jo.resize(ni*2);
|
||||
|
||||
CvMat _mp = cvMat(_err.reshape(2, 1));
|
||||
|
||||
if( calcJ )
|
||||
{
|
||||
CvMat _dpdr = cvMat(_Je.colRange(0, 3));
|
||||
CvMat _dpdt = cvMat(_Je.colRange(3, 6));
|
||||
CvMat _dpdf = cvMat(_Ji.colRange(0, 2));
|
||||
CvMat _dpdc = cvMat(_Ji.colRange(2, 4));
|
||||
CvMat _dpdk = cvMat(_Ji.colRange(4, NINTRINSIC));
|
||||
CvMat _dpdo = cvMat(_Jo.colRange(0, ni * 3));
|
||||
CvMat _mp = cvMat(_err.reshape(2, 1));
|
||||
CvMat _dpdo = _Jo.empty() ? CvMat() : cvMat(_Jo.colRange(0, ni * 3));
|
||||
|
||||
if( calcJ )
|
||||
{
|
||||
cvProjectPoints2Internal( &_Mi, &_ri, &_ti, &matA, &_k, &_mp, &_dpdr, &_dpdt,
|
||||
(flags & CALIB_FIX_FOCAL_LENGTH) ? 0 : &_dpdf,
|
||||
(flags & CALIB_FIX_PRINCIPAL_POINT) ? 0 : &_dpdc, &_dpdk,
|
||||
&_dpdo,
|
||||
(flags & CALIB_FIX_FOCAL_LENGTH) ? nullptr : &_dpdf,
|
||||
(flags & CALIB_FIX_PRINCIPAL_POINT) ? nullptr : &_dpdc, &_dpdk,
|
||||
(_Jo.empty()) ? nullptr: &_dpdo,
|
||||
(flags & CALIB_FIX_ASPECT_RATIO) ? aspectRatio : 0);
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user