pythonopencvcamera-calibration

Meaning of the retval return value in cv2.CalibrateCamera


as the title says, my question is about a return value given by the calibrateCamera function from OpenCv.

http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html

I have a functionnal implementation in python to find the intrinsic parameters and the distorsion coefficients of a Camera using a Black&White grid.

The question is more about the retval returned by the function. If i understood correctly it is the "the average re-projection error. This number gives a good estimation of precision of the found parameters. This should be as close to zero as possible." as mentionned in

http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration/camera_calibration.html

What exactly does a value close as close to zero as possible mean?

For example when i do it for my Logitech webcam:

RMS: 0.702660793513

camera matrix:

[[ 616.30868126    0.          339.02126978]
 [   0.          605.08224927  241.64607568]
 [   0.            0.            1.        ]]

Distortion coefficients:

[ 0.19805527 -0.62915986  0.00924648  0.02618232  1.02491764]

In this case, How does the error quantify the quality of the intrinsic parameters estimation?

EDIT:

So i went looking for answers and digging a bit deeper and checking the cpp implementation of this function.

This is the function computing this error value :

static double computeReprojectionErrors(
        const vector<vector<Point3f> >& objectPoints,
        const vector<vector<Point2f> >& imagePoints,
        const vector<Mat>& rvecs, const vector<Mat>& tvecs,
        const Mat& cameraMatrix, const Mat& distCoeffs,
        vector<float>& perViewErrors )
{
    vector<Point2f> imagePoints2;
    int i, totalPoints = 0;
    double totalErr = 0, err;
    perViewErrors.resize(objectPoints.size());

    for( i = 0; i < (int)objectPoints.size(); i++ )
    {
        projectPoints(Mat(objectPoints[i]), rvecs[i], tvecs[i],
                      cameraMatrix, distCoeffs, imagePoints2);
        err = norm(Mat(imagePoints[i]), Mat(imagePoints2), NORM_L2);
        int n = (int)objectPoints[i].size();
        perViewErrors[i] = (float)std::sqrt(err*err/n);
        totalErr += err*err;
        totalPoints += n;
    }

    return std::sqrt(totalErr/totalPoints);
}

This error is computed considering the tvecs and rvecs found with cv2.CalibrateCamera, it reproject the points used for finding those translation and rotation vectors and computes the euclidian distance between the reprojected point and the actual coordinates of those points.

I don't think this error is bounded in [0,1] but is instead depending on the range of the coordinates used for the calibration. So it's depending on the resolution of the images used for the calibration.

Can someone confirm/refute this?


Solution

  • The calibrateCamera(...) function returns the root mean square (RMS) re-projection error, typically expected to fall between 0.1 and 1.0 pixels for a good calibration. This involves projecting the 3D chessboard points (objectPoints) onto the image plane using the calibration parameters (i.e. cameraMatrix, distCoeffs, rvecs and tvecs), then comparing these projections with the known positions of the corner points (imagePoints).

    An RMS error of 1.0 implies that, on average, each projected point deviates by 1.0 pixel from its actual position. It's important to note that the error isn't bounded within the range [0, 1]; rather, it can be interpreted as a distance measure.