-1

I came across an error during execute stereoCalibrate in Opencv 2.4.11, which is says :

OpenCV Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == Size(cols, rows)) in cv::_OutputArray::create,

I think this must be some size error between these parameters, which go through them one by one. But there is still error. I hope someone awesome could find the error from the assembly code below. Here is the method call in my code.

double error = cv::stereoCalibrate(
        objPoints, cali0.imgPoints, cali1.imgPoints,
        camera0.intr.cameraMatrix, camera0.intr.distCoeffs,
        camera1.intr.cameraMatrix, camera1.intr.distCoeffs,
        cv::Size(1920,1080), m.rvec, m.tvec, m.evec, m.fvec,
        cv::TermCriteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 100, 1e-5)
        ,CV_CALIB_FIX_INTRINSIC + CV_CALIB_USE_INTRINSIC_GUESS
    );

In my code, m.rvec is (3,3,CV_64F), m.tvec is (3,1,CV_64F), m.evec and m.fvec are not preallocated which is same with the stereoCalibrate example. And intr.cameraMatrix is (3,3,CV_64F) and intr.distCoeffs is (8,1,CV_64F), objPoints is computed from the checkerboard which stores the 3d position of corners and all z value for point is zero.

After reading advice from @Josh, I modify the code as plain output mat object which are in CV_64F, but it still throws this assertion.

cv::Mat R, t, e, f;
    double error = cv::stereoCalibrate(
        objPoints, cali0.imgPoints, cali1.imgPoints,
        camera0.intr.cameraMatrix, camera0.intr.distCoeffs,
        camera1.intr.cameraMatrix, camera1.intr.distCoeffs,
        cali0.imgSize, R, t, e, f,
        cv::TermCriteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 100, 1e-5));

Finally I solved this problem, as a reminder, make sure the camera parameters you passed in are not const type....

  • The assembly you've shown doesn't seem to be relevant to your problem. You need to show a complete source code example that demonstrates the problem, specifically a Minimal, Complete and Verifiable Example. Too hazard a guess, the assertion failed message seems to be saying one of your `_OutputArray` objects doesn't have the size it's supposed to have. – Ross Ridge Oct 20 '16 at 21:18
  • Thank you Ross, your advice is really helpful which makes me start searching the source code. This is really no relative from the assembly, assembly only shows me the location of parameter which leads to the assertion. I will pay more attention on the post next time. : ) – EdwinDebuger Oct 26 '16 at 17:23

1 Answers1

1

Why go for assembly? OpenCV is open source and you can check the code you're calling here: https://github.com/opencv/opencv/blob/master/modules/calib3d/src/calibration.cpp#L3523

If you get assertion fails in OpenCV it's usually because you've passed a matrix with an incorrect shape. OpenCV is extremely picky. The assertion fail is on an OutputArray, so checking the function signature there are four possible culprits:

OutputArray _Rmat, OutputArray _Tmat, OutputArray _Emat, OutputArray _Fmat

The sizing is done inside cv::stereoCalibrate here:

https://github.com/opencv/opencv/blob/master/modules/calib3d/src/calibration.cpp#L3550

_Rmat.create(3, 3, rtype);
_Tmat.create(3, 1, rtype);

<-- snipped -->

if( _Emat.needed() )
{
    _Emat.create(3, 3, rtype);
    p_matE = &(c_matE = _Emat.getMat());
}
if( _Fmat.needed() )
{
    _Fmat.create(3, 3, rtype);
    p_matF = &(c_matF = _Fmat.getMat());

}

The assertion is being triggered in one of these calls, the code is here:

https://github.com/opencv/opencv/blob/master/modules/core/src/matrix.cpp#L2241

Try passing in plain Mat objects without preallocating their shape.

Josh
  • 2,658
  • 31
  • 36
  • Thank you very much Josh!!! I just figure that camera parameters are also belongs to outputArray, which makes me realize that I can't pass camera parameters as const object. Then the problem is solved! Thank you so much for the detailed explanation, which helps me a lot and give me a clue that how to debug from the source code : ) – EdwinDebuger Oct 26 '16 at 17:18