CV_IS_MAT assertion in cv::stereoRectify

asked 2014-06-10 05:29:52 -0600

fragles1991 gravatar image

Hello guys,

I'm trying to get rectification transform and projection matrix for stereo images using cv::stereoRectify method.

But all the time I'm getting error:

OpenCV Error: Assertion failed (CV_IS_MAT(_distCoeffs) && (_distCoeffs->rows == 1 || _distCoeffs->cols == 1) && (_distCoeffs->rows_distCoeffs->cols == 4 || _distCoeffs->rows_distCoeffs->cols == 5 || _distCoeffs->rows*_distCoeffs->cols == 8)) in cvUndistortPoints, file /build/buildd/opencv-2.3.1/modules/imgproc/src/undistort.cpp, line 292

My code:

LOG(LINFO) << "Create bunch of fresh cv::Mat objects";
cv::StereoVar var;
cv::Mat Q;
cv::Mat R1, P1, R2, P2;
cv::Size img_size = oLeftImage.size();

// Rotation and Translation matrices between cameras
cv::Mat R;// = Types::MatrixTranslator::fromStr("1529.207571 0.000000 726.349884; 0.000000 1529.207571 535.944351; 0 0 1", CV_64F);
cv::Mat T;// = Types::MatrixTranslator::fromStr("-141.355314; 0; 0", CV_64F);

cv::FileStorage fs("/home/fragles1991/stereo/extrisinc.yml", cv::FileStorage::READ);

fs["R"] >> R;
fs["T"] >> T;

fs.release();

// Camera matrices
cv::Mat M1 = oLeftCamInfo.cameraMatrix();
cv::Mat M2 = oRightCamInfo.cameraMatrix();

//Distortion coefficients matrices
cv::Mat D1 = oLeftCamInfo.distCoeffs();
cv::Mat D2 = oRightCamInfo.distCoeffs();


LOG(LINFO) << "M1 "<< M1;
LOG(LINFO) << "M2 "<< M2;
LOG(LINFO) << "D1 "<< D1;
LOG(LINFO) << "D2 "<< D2;
LOG(LINFO) << "R "<< R;
LOG(LINFO) << "T "<< T;
LOG(LINFO) << "Size " << img_size.height << "x"<<img_size.width;
LOG(LINFO) << "Calculate stereo rectification maps";

const cv::Mat* _distCoeffs = &D1;

LOG(LINFO) << "MatSize " << _distCoeffs->rows << "x"<< _distCoeffs->cols << "=" << _distCoeffs->rows*_distCoeffs->cols;
//CV_Assert(CV_IS_MAT(&M1)); all these asserts fails
//CV_Assert(CV_IS_MAT(_distCoeffs));
//CV_Assert(_distCoeffs->rows == 1 || _distCoeffs->cols == 1);
//CV_Assert(_distCoeffs->rows*_distCoeffs->cols == 4 ||
//      _distCoeffs->rows*_distCoeffs->cols == 5 ||
//      _distCoeffs->rows*_distCoeffs->cols == 8 ||
//     _distCoeffs->rows*_distCoeffs->cols == 12);

cv::stereoRectify(M1, M2, D1, D2, img_size, R, T, R1, R2, P1, P2, Q, cv::CALIB_ZERO_DISPARITY, -1, img_size);

//delete _distCoeffs;


LOG(LINFO) << R1;
LOG(LINFO) << P1;
LOG(LINFO) << R2;
LOG(LINFO) << P2;

Full output:

INFO: Create bunch of fresh cv::Mat objects
INFO: M1 [1445.6954, 0, 622.89563;
  0, 1451.6072, 499.31015;
  0, 0, 1]
INFO: M2 [1491.7822, 0, 640.34027;
  0, 1497.3535, 519.7312;
  0, 0, 1]
INFO: D1 [-0.21336879, 0.13320319, 0.0017676279, -0.0021822718, 0]
INFO: D2 [-0.22215681, 0.14851353, -0.0011862318, -0.0016049357, 0]
INFO: R [1529.20751953125, 0, 726.349853515625;
  0, 1529.20751953125, 535.9443359375;
  0, 0, 1]
INFO: T [-141.3553161621094; 0; 0]
INFO: Size 1024x1280
INFO: Calculate stereo rectification maps
INFO: MatSize 1x5=5
OpenCV Error: Assertion failed (CV_IS_MAT(_distCoeffs) && (_distCoeffs->rows == 1 || _distCoeffs->cols == 1) && (_distCoeffs->rows*_distCoeffs->cols == 4 || _distCoeffs->rows*_distCoeffs->cols == 5 || _distCoeffs->rows*_distCoeffs->cols == 8)) in cvUndistortPoints, file /build/buildd/opencv-2.3.1/modules/imgproc/src/undistort.cpp, line 292
ERROR: Error occured in processing input
edit retag flag offensive close merge delete

Comments

1

Solved, stereoRectify parameters was in wrong order, should be M1,D1, M2,D2

fragles1991 gravatar imagefragles1991 ( 2014-06-10 06:07:00 -0600 )edit

thanks! Same issue here. :)

mojovski gravatar imagemojovski ( 2015-11-22 08:02:31 -0600 )edit