OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 19 Feb 2015 06:44:39 -0600Reprojection error with findFundamentalMathttp://answers.opencv.org/question/53955/reprojection-error-with-findfundamentalmat/ Hello,
Maybe my question is not really appropriate here.
As the function findFundamentalMat (with a RANSAC method) does not return the list of outliers, I was trying to use the fundamental matrix returned by the function to compute myself the reprojection error for the input points.
I looked into the [source code](https://github.com/Itseez/opencv/blob/master/modules/calib3d/src/ptsetreg.cpp) and I discovered that there is a function called findInliers which call computeError to compute the error for the input points using the fundamental matrix estimated in the current iteration.
When I checked this function:
const Point3f* from = m1.ptr<Point3f>();
const Point3f* to = m2.ptr<Point3f>();
const double* F = model.ptr<double>();
for(int i = 0; i < count; i++ )
{
const Point3f& f = from[i];
const Point3f& t = to[i];
double a = F[0]*f.x + F[1]*f.y + F[ 2]*f.z + F[ 3] - t.x;
double b = F[4]*f.x + F[5]*f.y + F[ 6]*f.z + F[ 7] - t.y;
double c = F[8]*f.x + F[9]*f.y + F[10]*f.z + F[11] - t.z;
errptr[i] = (float)std::sqrt(a*a + b*b + c*c);
}
for me model is the current estimated fundamental matrix which seems to have 12 elements instead of being a 3x3 matrix.
Is there a problem or am I missing something ? Can someone explain me the formula for computing the error ?
To compute the error, I think I will use the distance error between the real 2d location in the image to the corresponding epipolar line using the fundamental matrix for each input points, but I want to understand what is behind the formula used in the source code of OpenCV.
Thanks.
Edit:
I was wrong, [findFundamentalMat](http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findfundamentalmat) returns also the list of inliers in a cv::Mat with the C++ interface.Wed, 28 Jan 2015 07:44:52 -0600http://answers.opencv.org/question/53955/reprojection-error-with-findfundamentalmat/Answer by Eduardo for <p>Hello,</p>
<p>Maybe my question is not really appropriate here.</p>
<p>As the function findFundamentalMat (with a RANSAC method) does not return the list of outliers, I was trying to use the fundamental matrix returned by the function to compute myself the reprojection error for the input points.</p>
<p>I looked into the <a href="https://github.com/Itseez/opencv/blob/master/modules/calib3d/src/ptsetreg.cpp">source code</a> and I discovered that there is a function called findInliers which call computeError to compute the error for the input points using the fundamental matrix estimated in the current iteration.
When I checked this function:</p>
<pre><code>const Point3f* from = m1.ptr<Point3f>();
const Point3f* to = m2.ptr<Point3f>();
const double* F = model.ptr<double>();
for(int i = 0; i < count; i++ )
{
const Point3f& f = from[i];
const Point3f& t = to[i];
double a = F[0]*f.x + F[1]*f.y + F[ 2]*f.z + F[ 3] - t.x;
double b = F[4]*f.x + F[5]*f.y + F[ 6]*f.z + F[ 7] - t.y;
double c = F[8]*f.x + F[9]*f.y + F[10]*f.z + F[11] - t.z;
errptr[i] = (float)std::sqrt(a*a + b*b + c*c);
}
</code></pre>
<p>for me model is the current estimated fundamental matrix which seems to have 12 elements instead of being a 3x3 matrix.
Is there a problem or am I missing something ? Can someone explain me the formula for computing the error ?</p>
<p>To compute the error, I think I will use the distance error between the real 2d location in the image to the corresponding epipolar line using the fundamental matrix for each input points, but I want to understand what is behind the formula used in the source code of OpenCV.</p>
<p>Thanks.</p>
<p>Edit:
I was wrong, <a href="http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findfundamentalmat">findFundamentalMat</a> returns also the list of inliers in a cv::Mat with the C++ interface.</p>
http://answers.opencv.org/question/53955/reprojection-error-with-findfundamentalmat/?answer=55673#post-id-55673I was utterly wrong. I don't know what happened in my mind at this time but I looked at the wrong function to compute the error.
The part of code I quoted comes from the function ([computeError](https://github.com/Itseez/opencv/blob/master/modules/calib3d/src/ptsetreg.cpp#L455)) for Affine3DEstimator and compute the error distance vector for two sets of 3D points and with the estimated 3D affine transformation matrix.
The correct function called to compute the distance error to find inliers with Ransac findFundamentalMat is this [one](https://github.com/Itseez/opencv/blob/master/modules/calib3d/src/fundam.cpp#L623). In this case, the distance error is the maximum squared distance between the 2D image point and the corresponding epipolar line between the left and the right images.Thu, 19 Feb 2015 06:44:39 -0600http://answers.opencv.org/question/53955/reprojection-error-with-findfundamentalmat/?answer=55673#post-id-55673