Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 861
David Avatar asked Apr 14 '15 13:04

David


People also ask

What is the output of camera calibration?

In summary, a camera calibration algorithm has the following inputs and outputs. Inputs : A collection of images with points whose 2D image coordinates and 3D world coordinates are known. Outputs: The 3×3 camera intrinsic matrix, the rotation and translation of each image.

Which module of OpenCV includes 3D reconstruction and calibration?

OpenCV: Camera calibration and 3D reconstruction (calib3d module)


1 Answers

calibrateCamera returns the root mean square (RMS) re-projection error, usually it should be between 0.1 and 1.0 pixels in a good calibration.
The calculation is done by projecting the 3D chessboard points (objectPoints) into the image plane using the final set of calibration parameters (cameraMatrix, distCoeffs, rvecs and tvecs) and comparing the known position of the corners (imagePoints).

An RMS error of 1.0 means that, on average, each of these projected points is 1.0 px away from its actual position. The error is not bounded in [0, 1], it can be considered as a distance.

like image 131
Kornel Avatar answered Oct 21 '22 02:10

Kornel