diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index 1bd896463c..2e9f07a274 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -2085,7 +2085,7 @@ void cv::drawChessboardCorners( InputOutputArray _image, Size patternSize, Mat corners = _corners.getMat(); if( corners.empty() ) return; - Mat image = _image.getMat(); CvMat c_image = _image.getMat(); + Mat image = _image.getMat(); CvMat c_image = image; int nelems = corners.checkVector(2, CV_32F, true); CV_Assert(nelems >= 0); cvDrawChessboardCorners( &c_image, patternSize, corners.ptr(), diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index c4c38be95f..b90e71c245 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -3234,54 +3234,20 @@ void cv::composeRT( InputArray _rvec1, InputArray _tvec1, c_tvec2 = tvec2, c_rvec3 = rvec3, c_tvec3 = tvec3; CvMat c_dr3dr1, c_dr3dt1, c_dr3dr2, c_dr3dt2, c_dt3dr1, c_dt3dt1, c_dt3dr2, c_dt3dt2; CvMat *p_dr3dr1=0, *p_dr3dt1=0, *p_dr3dr2=0, *p_dr3dt2=0, *p_dt3dr1=0, *p_dt3dt1=0, *p_dt3dr2=0, *p_dt3dt2=0; - - if( _dr3dr1.needed() ) - { - _dr3dr1.create(3, 3, rtype); - p_dr3dr1 = &(c_dr3dr1 = _dr3dr1.getMat()); - } - - if( _dr3dt1.needed() ) - { - _dr3dt1.create(3, 3, rtype); - p_dr3dt1 = &(c_dr3dt1 = _dr3dt1.getMat()); - } - - if( _dr3dr2.needed() ) - { - _dr3dr2.create(3, 3, rtype); - p_dr3dr2 = &(c_dr3dr2 = _dr3dr2.getMat()); - } - - if( _dr3dt2.needed() ) - { - _dr3dt2.create(3, 3, rtype); - p_dr3dt2 = &(c_dr3dt2 = _dr3dt2.getMat()); - } - - if( _dt3dr1.needed() ) - { - _dt3dr1.create(3, 3, rtype); - p_dt3dr1 = &(c_dt3dr1 = _dt3dr1.getMat()); - } - - if( _dt3dt1.needed() ) - { - _dt3dt1.create(3, 3, rtype); - p_dt3dt1 = &(c_dt3dt1 = _dt3dt1.getMat()); - } - - if( _dt3dr2.needed() ) - { - _dt3dr2.create(3, 3, rtype); - p_dt3dr2 = &(c_dt3dr2 = _dt3dr2.getMat()); +#define CV_COMPOSE_RT_PARAM(name) \ + Mat name; \ + if (_ ## name.needed())\ + { \ + _ ## name.create(3, 3, rtype); \ + name = _ ## name.getMat(); \ + p_ ## name = &(c_ ## name = name); \ } - if( _dt3dt2.needed() ) - { - _dt3dt2.create(3, 3, rtype); - p_dt3dt2 = &(c_dt3dt2 = _dt3dt2.getMat()); - } + CV_COMPOSE_RT_PARAM(dr3dr1); CV_COMPOSE_RT_PARAM(dr3dt1); + CV_COMPOSE_RT_PARAM(dr3dr2); CV_COMPOSE_RT_PARAM(dr3dt2); + CV_COMPOSE_RT_PARAM(dt3dr1); CV_COMPOSE_RT_PARAM(dt3dt1); + CV_COMPOSE_RT_PARAM(dt3dr2); CV_COMPOSE_RT_PARAM(dt3dt2); +#undef CV_COMPOSE_RT_PARAM cvComposeRT(&c_rvec1, &c_tvec1, &c_rvec2, &c_tvec2, &c_rvec3, &c_tvec3, p_dr3dr1, p_dr3dt1, p_dr3dr2, p_dr3dt2, @@ -3306,7 +3272,8 @@ void cv::projectPoints( InputArray _opoints, CvMat *pdpdrot=0, *pdpdt=0, *pdpdf=0, *pdpdc=0, *pdpddist=0; _ipoints.create(npoints, 1, CV_MAKETYPE(depth, 2), -1, true); - CvMat c_imagePoints = _ipoints.getMat(); + Mat imagePoints = _ipoints.getMat(); + CvMat c_imagePoints(imagePoints); CvMat c_objectPoints = opoints; Mat cameraMatrix = _cameraMatrix.getMat(); @@ -3674,24 +3641,25 @@ cv::Vec3d cv::RQDecomp3x3( InputArray _Mmat, Mat M = _Mmat.getMat(); _Rmat.create(3, 3, M.type()); _Qmat.create(3, 3, M.type()); + Mat Rmat = _Rmat.getMat(); + Mat Qmat = _Qmat.getMat(); Vec3d eulerAngles; - CvMat matM = M, matR = _Rmat.getMat(), matQ = _Qmat.getMat(), Qx, Qy, Qz, *pQx=0, *pQy=0, *pQz=0; - if( _Qx.needed() ) - { - _Qx.create(3, 3, M.type()); - pQx = &(Qx = _Qx.getMat()); - } - if( _Qy.needed() ) - { - _Qy.create(3, 3, M.type()); - pQy = &(Qy = _Qy.getMat()); - } - if( _Qz.needed() ) - { - _Qz.create(3, 3, M.type()); - pQz = &(Qz = _Qz.getMat()); - } + CvMat matM = M, matR = Rmat, matQ = Qmat; +#define CV_RQDecomp3x3_PARAM(name) \ + Mat name; \ + CvMat c_ ## name, *p ## name = NULL; \ + if( _ ## name.needed() ) \ + { \ + _ ## name.create(3, 3, M.type()); \ + name = _ ## name.getMat(); \ + c_ ## name = name; p ## name = &c_ ## name; \ + } + + CV_RQDecomp3x3_PARAM(Qx); + CV_RQDecomp3x3_PARAM(Qy); + CV_RQDecomp3x3_PARAM(Qz); +#undef CV_RQDecomp3x3_PARAM cvRQDecomp3x3(&matM, &matR, &matQ, pQx, pQy, pQz, (CvPoint3D64f*)&eulerAngles[0]); return eulerAngles; } @@ -3709,28 +3677,28 @@ void cv::decomposeProjectionMatrix( InputArray _projMatrix, OutputArray _cameraM _cameraMatrix.create(3, 3, type); _rotMatrix.create(3, 3, type); _transVect.create(4, 1, type); - CvMat c_projMatrix = projMatrix, c_cameraMatrix = _cameraMatrix.getMat(); - CvMat c_rotMatrix = _rotMatrix.getMat(), c_transVect = _transVect.getMat(); - CvMat c_rotMatrixX, *p_rotMatrixX = 0; - CvMat c_rotMatrixY, *p_rotMatrixY = 0; - CvMat c_rotMatrixZ, *p_rotMatrixZ = 0; + Mat cameraMatrix = _cameraMatrix.getMat(); + Mat rotMatrix = _rotMatrix.getMat(); + Mat transVect = _transVect.getMat(); + CvMat c_projMatrix = projMatrix, c_cameraMatrix = cameraMatrix; + CvMat c_rotMatrix = rotMatrix, c_transVect = transVect; CvPoint3D64f *p_eulerAngles = 0; - if( _rotMatrixX.needed() ) - { - _rotMatrixX.create(3, 3, type); - p_rotMatrixX = &(c_rotMatrixX = _rotMatrixX.getMat()); - } - if( _rotMatrixY.needed() ) - { - _rotMatrixY.create(3, 3, type); - p_rotMatrixY = &(c_rotMatrixY = _rotMatrixY.getMat()); - } - if( _rotMatrixZ.needed() ) - { - _rotMatrixZ.create(3, 3, type); - p_rotMatrixZ = &(c_rotMatrixZ = _rotMatrixZ.getMat()); +#define CV_decomposeProjectionMatrix_PARAM(name) \ + Mat name; \ + CvMat c_ ## name, *p_ ## name = NULL; \ + if( _ ## name.needed() ) \ + { \ + _ ## name.create(3, 3, type); \ + name = _ ## name.getMat(); \ + c_ ## name = name; p_ ## name = &c_ ## name; \ } + + CV_decomposeProjectionMatrix_PARAM(rotMatrixX); + CV_decomposeProjectionMatrix_PARAM(rotMatrixY); + CV_decomposeProjectionMatrix_PARAM(rotMatrixZ); +#undef CV_decomposeProjectionMatrix_PARAM + if( _eulerAngles.needed() ) { _eulerAngles.create(3, 1, CV_64F, -1, true); diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index 55618c27e4..0f0740510b 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -1306,7 +1306,8 @@ void CV_ProjectPointsTest_C::project( const Mat& opoints, const Mat& rvec, const dpdf.create(npoints*2, 2, CV_64F); dpdc.create(npoints*2, 2, CV_64F); dpddist.create(npoints*2, distCoeffs.rows + distCoeffs.cols - 1, CV_64F); - CvMat _objectPoints = opoints, _imagePoints = Mat(ipoints); + Mat imagePoints(ipoints); + CvMat _objectPoints = opoints, _imagePoints = imagePoints; CvMat _rvec = rvec, _tvec = tvec, _cameraMatrix = cameraMatrix, _distCoeffs = distCoeffs; CvMat _dpdrot = dpdrot, _dpdt = dpdt, _dpdf = dpdf, _dpdc = dpdc, _dpddist = dpddist;