horrible calibration results

asked 2015-10-19 04:38:49 -0600

maxfa gravatar image

Hi,

I tried to integrate the calibration sample in my program but the results I'm getting are quite horrible. I think I've copied the essential parts correctly but the results are just wrong. For my webcam (which i believe has near 0 distortion) the results are decent but for my ip camera with 98 degree fov x the results are completely random (spherical distortion with holes in it sometimes)image description

As you can see that can't be right. I've read all the dovumentation i could find but can't find anything that could cause this. (I've tried to swap Cols/Rows and all the flags etc)

The code

void Worker::runCalibration(){

calibChessFound = findChessboardCorners( iMat, Size(calibCols,calibRows), calibPointBuf,
                               CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FAST_CHECK | CV_CALIB_CB_NORMALIZE_IMAGE);
if(calibChessFound){
    flashTime = QTime::currentTime().msec();
    Mat iMatGray;
    cvtColor(iMat,iMatGray,CV_BGR2GRAY);
    cornerSubPix(iMatGray,calibPointBuf,Size(11,11),Size(-1,-1),TermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,0.1));

    calibImagePoints.push_back(calibPointBuf);

    int flags=0;
    if(calibFAR){flags = flags|CV_CALIB_FIX_ASPECT_RATIO;}
    if(calibFPP){flags = flags|CV_CALIB_FIX_PRINCIPAL_POINT;}
    if(calibAZT){flags = flags|CV_CALIB_ZERO_TANGENT_DIST;}

    if(calibImagePoints.size() > 10){

        calibCamMat = Mat::eye(3, 3, CV_64F);
        if( calibFAR ){
            calibCamMat.at<double>(0,0) = iMat.cols/iMat.rows;
        }
        calibDistCoeffs = Mat::zeros(8, 1, CV_64F);

        vector<vector<Point3f> > objectPoints(1);
        calcBoardCornerPositions(Size(calibCols,calibRows), calibSize, objectPoints[0]);
        objectPoints.resize(calibImagePoints.size(),objectPoints[0]);

        double rms = calibrateCamera(objectPoints, calibImagePoints, iMat.size(), calibCamMat,
                        calibDistCoeffs, rvecs, tvecs, flags|CALIB_FIX_K4|CALIB_FIX_K5);
                        //*|CALIB_FIX_K3*/|CALIB_FIX_K4|CALIB_FIX_K5);
        emit error("RMS error of camera calibration is, rms = "+QString::number(rms),1);
        bool ok = checkRange(calibCamMat) && checkRange(calibDistCoeffs);
        if(!ok){
            emit error("INVALID VALUES @ Worker::runCalibration",1);
        }else{
            initUndistortRectifyMap(calibCamMat,calibDistCoeffs,Mat(),
                                    getOptimalNewCameraMatrix(calibCamMat,calibDistCoeffs,iMat.size(),1),
                                    iMat.size(),CV_16SC2,defLensMap1,defLensMap2);
        }
    }

}
}

Any ideas? I'm running out of the fast.

Thanks!

edit retag flag offensive close merge delete

Comments

2

Your FOV is 98 deg, have you tried fisheye calibration?

Throwaway99 gravatar imageThrowaway99 ( 2015-10-19 17:38:49 -0600 )edit

I have not tried that. However looking at the images on the site you linked it seems that I should be able to get decent results even with the perspective model which I'm not getting. My code works occasionaly but most of the time i get those spheres with holes.

maxfa gravatar imagemaxfa ( 2015-10-21 13:50:19 -0600 )edit

When I have to do a calibration it usually takes me quite a few tries before I get good results. So, to expect it to work every time might be an unreasonable expectation?

Der Luftmensch 2 gravatar imageDer Luftmensch 2 ( 2015-10-24 10:41:46 -0600 )edit

okay. I have given it close to a hundrer tries and never quite gotten it perfect yet. I will keep trying then :/ it just seems so easy in the examples online.

maxfa gravatar imagemaxfa ( 2015-10-26 08:27:26 -0600 )edit

See this http://answers.opencv.org/question/28... question and answer and the comments too. I was able to "solve" this problem and get consistently good results by zooming in. It seems that the extreme radial distortion is the culprit. Also, I started using a rig to have my chessboard stable for every shot. I'm not sure if this made a big difference did, but I know that decreasing the radial distortion by zooming definitely did.

mannyglover gravatar imagemannyglover ( 2016-12-22 16:24:36 -0600 )edit