cv2.CalibrateCamera中的retval返回值的含义 [英] Meaning of the retval return value in cv2.CalibrateCamera

查看:638
本文介绍了cv2.CalibrateCamera中的retval返回值的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所示,我的问题是有关OpenCv的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

我在python中有一个函数实现,可以使用Black& White网格找到Camera的固有参数和失真系数.

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

问题更多是关于该函数返回的retval.如果我正确理解的话,那就是平均重投影误差.这个数字可以很好地估计找到的参数的精度.它应该尽可能接近零."

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?

例如,当我为Logitech网络摄像头拍摄时:

For example when i do it for my Logitech webcam:

RMS:0.702660793513

相机矩阵:

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

失真系数:

[ 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?

所以我去寻找答案,并进行了更深入的研究,并检查了该功能的cpp实现.

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);
}

考虑到使用cv2.CalibrateCamera找到的tvecs和rvecs来计算此错误,它将对用于查找这些平移和旋转矢量的点进行重新投影,并计算重新投影的点与这些点的实际坐标之间的欧几里得距离.

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.

我认为此错误不受[0,1]的限制,而是取决于用于校准的坐标范围.因此,这取决于用于校准的图像的分辨率.

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?

推荐答案

calibrateCamera返回均方根(RMS)重投影误差,在良好的校准中通常应在0.1到1.0像素之间.
通过使用最终的一组校准参数(cameraMatrixdistCoeffsrvecstvecs)将3D棋盘点(objectPoints)投影到图像平面中并比较已知的位置来完成计算.角(imagePoints).

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).

RMS误差为1.0意味着平均而言,这些投影点中的每个投影点都偏离其实际位置1.0 px.该错误不受[0,1]的限制,可以将其视为距离.

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.

这篇关于cv2.CalibrateCamera中的retval返回值的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆