0

下面的代码是 OpenCV 的相机校准部分。我只想改变一点:变量err是使用欧几里得距离公式计算的sqrt(x-coordinate diff^2+y-coordinate diff^2),但我只想考虑 x 坐标差异。所以我重写了它

err = sqrt((imagePoints[i].x - imagePoints2.x) ^ 2);

imagePoints[i]但是,我收到错误,因为我无法访问&的向量的 x 坐标值imagepoints2

err有人可以帮助仅考虑 x 坐标增量来重写变量吗?

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, bool fisheye)
{

    vector<Point2f> imagePoints2;
    size_t totalPoints = 0;
    double totalErr = 0, err;
    perViewErrors.resize(objectPoints.size());

    for (size_t i = 0; i < objectPoints.size(); ++i)
    {
        if (fisheye)
        {
            fisheye::projectPoints(objectPoints[i], imagePoints2, rvecs[i],            tvecs[i], cameraMatrix,  distCoeffs);
        }
        else
        {
            projectPoints(objectPoints[i], rvecs[i], tvecs[i], cameraMatrix, distCoeffs, imagePoints2);
        }
        err = norm(imagePoints[i], imagePoints2, NORM_L2);

        size_t n = objectPoints[i].size();
        perViewErrors[i] = (float)std::sqrt(err*err / n);
        totalErr += err*err;
        totalPoints += n;
    }

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

0 回答 0