From def2256609077475adb3760c38dab4af362f2311 Mon Sep 17 00:00:00 2001 From: Alexander Duda Date: Fri, 12 Jun 2015 13:50:43 +0200 Subject: [PATCH] cv::stereoRectify: fix segfault in case of empty distCoeffs cvStereoRectify assumes that NULL is provided in case of no distCoeffs --- modules/calib3d/src/calibration.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index 98deab6396..5dcd274e34 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -2194,7 +2194,7 @@ void cvStereoRectify( const CvMat* _cameraMatrix1, const CvMat* _cameraMatrix2, for( k = 0; k < 2; k++ ) { const CvMat* A = k == 0 ? _cameraMatrix1 : _cameraMatrix2; const CvMat* Dk = k == 0 ? _distCoeffs1 : _distCoeffs2; - double dk1 = Dk ? cvmGet(Dk, 0, 0) : 0; + double dk1 = Dk && Dk->data.ptr ? cvmGet(Dk, 0, 0) : 0; double fc = cvmGet(A,idx^1,idx^1); if( dk1 < 0 ) { fc *= 1 + dk1*(nx*nx + ny*ny)/(4*fc*fc); @@ -3372,7 +3372,9 @@ void cv::stereoRectify( InputArray _cameraMatrix1, InputArray _distCoeffs1, p_Q = &(c_Q = _Qmat.getMat()); } - cvStereoRectify( &c_cameraMatrix1, &c_cameraMatrix2, &c_distCoeffs1, &c_distCoeffs2, + CvMat *p_distCoeffs1 = distCoeffs1.empty() ? NULL : &c_distCoeffs1; + CvMat *p_distCoeffs2 = distCoeffs2.empty() ? NULL : &c_distCoeffs2; + cvStereoRectify( &c_cameraMatrix1, &c_cameraMatrix2, p_distCoeffs1, p_distCoeffs2, imageSize, &c_R, &c_T, &c_R1, &c_R2, &c_P1, &c_P2, p_Q, flags, alpha, newImageSize, (CvRect*)validPixROI1, (CvRect*)validPixROI2); }