以下代码是OpenCV摄像机校准的一部分。我只想稍微改变一下:使用欧几里德距离公式err
计算变量sqrt(x-coordinate diff^2+y-coordinate diff^2)
,但我只想考虑x坐标差异。所以我重新写了它
err = sqrt((imagePoints[i].x - imagePoints2.x) ^ 2);
然而,我收到错误,因为我无法访问imagePoints[i]
&的向量的x坐标值。 imagepoints2
。
只考虑x坐标增量,有人可以帮助重写变量err
吗?
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);
}