OpenCV calibrateCamera assertion failed

妖精的绣舞 提交于 2019-12-06 14:27:44

问题


So I am having basically the same issue described in this post from last year, and am not getting anywhere with solving it. I am calling calibrateCamera and am getting the error "Assertion failed (nimages > 0 && nimages == (int) imagePoints1.total() && (!imgPtMat2 || nimages == (int)imagePoints2.total()) in cv::collectCalibrationData".

The line of code that is getting this error is:

double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix,
    distCoeffs, rvecs, tvecs, s.flag | CALIB_FIX_K4 | CALIB_FIX_K5);

I have checked the size of both objectPoints and imagePoints, and they are the same, as shown in the images below.

Both imagePoints and objectPoints contain points that make sense-- they are not filled with incorrect values or empty. I took a look at the collectCalibrationData code because that was where the assertion was failing, and it seems my problem is that the function itself seems to calculate the size of each vector incorrectly, or at least in a way that does not give a consistent size. Code for relevant part of function collectcalibrationData shown below:

static void collectCalibrationData( InputArrayOfArrays objectPoints,
                                InputArrayOfArrays imagePoints1,
                                InputArrayOfArrays imagePoints2,
                                Mat& objPtMat, Mat& imgPtMat1, Mat* imgPtMat2,
                                Mat& npoints )
{
int nimages = (int)objectPoints.total();
int i, j = 0, ni = 0, total = 0;
CV_Assert(nimages > 0 && nimages == (int)imagePoints1.total() &&
    (!imgPtMat2 || nimages == (int)imagePoints2.total()));

for( i = 0; i < nimages; i++ )
{
    ni = objectPoints.getMat(i).checkVector(3, CV_32F);
    if( ni <= 0 )
        CV_Error(CV_StsUnsupportedFormat, "objectPoints should contain vector of vectors of points of type Point3f");
    int ni1 = imagePoints1.getMat(i).checkVector(2, CV_32F);
    if( ni1 <= 0 )
        CV_Error(CV_StsUnsupportedFormat, "imagePoints1 should contain vector of vectors of points of type Point2f");
    CV_Assert( ni == ni1 );

    total += ni;
}

It seems that the size of each of the vectors is calculated with nimages = (int)objectPoints.total() and nimages == (int)imagePoints.total(). I print out the values these produce with these two lines (converting the vectors to InputArrayofArrays b/c that's what collectCalibrationData does):

cv::InputArrayOfArrays IMGPOINT = imagePoints; std::cout << (int) IMGPOINT.total() << std::endl;
cv::InputArrayOfArrays OBJPOINT = objectPoints; std::cout << (int) OBJPOINT.total() << std::endl;   

These statements produce a seemingly random integer every time I run the program-- they are not consistent and are never equal to each other. At this point, I'm stuck. I'm not sure why collectCalibrationData is getting the wrong values for the size of my vectors, and why converting the vectors to an InputArrayofArrays seems to change their size. Any tips? I've seen this problem asked once or twice before but there's never been an answer.

I am using VS 2013 and OpenCV 3.0.0.

来源:https://stackoverflow.com/questions/31483143/opencv-calibratecamera-assertion-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!