Residual error from fundamental matrix [closed]
Hi guys,
as in the previous topics I made I'm still working on self calibration stuff. I'm generating the data for the evaluation but I end out with some strange error computing the residual error as defined here slide 31. But maybe I'm using the wrong function to compute the norm. The resulting residual error is absurd, while the epipolar equation x'Fx=0 give to me a residual of 0.25 so I suppose is almost perfect.
I've points correspondences for image L and R and the fundamental matrix. Actually I'm doing in this way, I don't care that it isn't efficient since is not important, is just for data generation.
for(int i=0; i<maskInliers.rows; i++)
{
if((uchar)maskInliers.at<uchar>(i) == 1)
{
inliersL.push_back(featuresL.at(i));
inliersR.push_back(featuresR.at(i));
cv::Mat temp_point_1 = cv::Mat(3,1,CV_64F);
temp_point_1.at<double>(0,0) = featuresL.at(i).x;
temp_point_1.at<double>(1,0) = featuresL.at(i).y;
temp_point_1.at<double>(2,0) = 1;
cv::Mat temp_point_2 = cv::Mat(3,1,CV_64F);
temp_point_2.at<double>(0,0) = featuresR.at(i).x;
temp_point_2.at<double>(1,0) = featuresR.at(i).y;
temp_point_2.at<double>(2,0) = 1;
/*******************************
* COMPUTING THE F RESIDUALS
*******************************/
//Epipolar equation x'Fx=0
cv::Mat tempResF = temp_point_2.t()*fundamentalMat*temp_point_1;
residualF += fabs(tempResF.at<double>(0,0));
//Residual error
double resError = cv::norm(temp_point_2-(fundamentalMat*temp_point_1)) +
cv::norm(temp_point_1-(fundamentalMat.t()*temp_point_2));
residualF_error += resError;
}
}
I would like to find the residual error, is there any built in function to do that? I've looked on the documentation but I've not find it.
EDIT: the result I'm getting are the following:
Residual of F 0.250138
Mean residual of F 0.0039084
F RESIDUAL ERROR: 65237.2
where:
- Residual of F is computed using the epipolar geometry x'Fx=0
- mean error is the previous value divided by the number of inliers used for estimating the fundamental matrix
- The last one (F RESIDUAL ERROR) is the one that is wrong and that I'm asking about
That is OpenCV2 not OpenCV 3. The book is too old for you.
Which book are you talking about? I don't get the point. I just linked a presentation for reference, the formula I suppose is still the same :-D I edited the question adding some result that I got.
You don't understand about pdf. It is showing on front cover dating back to 2010.. It it marking on OpenCV II not OpenCV III. The code is not same as OpenCV 3 and OpenCV 4. OpenCV 2 will worked on OpenCV4(same code), but not OpenCV 3
You haven't stating which version.
I don't get this code from the pdf, it is mine. I just linked the pdf as a reference for the residual error formula (slide 31), you can forget the PDF, it doesn't matter at all in my work, neither I used it. The same formula can be found on HZ book for example. The point of my question is that I don't get the correct results (using the attached code) despite the residuals based on the fundamental matrix equation are good. By the way, I'm using OpenCV 3.
Ok! Are you looping? This can't be right
temp_point_1.at<double>(0,0) = featuresL.at(i).x;
If you're literatior this should be like thistemp_point_1.at<double>(0, i) = featuresL.at(i).x;
I had some like this:
Yes, I'm looping. Basically I loop thru the features arrays, and if the point is an inlier (based on the mask value from
findFundamentalMat
) then I put the point of L and R in a temporary matrix,temp_point_1
andtemp_point_2
and then from that I compute the residual for each point. What does it change if the matrix have 1 or let's say, N column? You suggest to me to put every point in a matrix that at the end should be 3xN with N the number of inliers. Then how I can find the residual error?B=H*A
so basically is going to beB=F*A
? And as a resultF.t()*B = A
, and here I'm in (and this is what I'm actually doing), but how to compute the residual error? To be clearer I'm going to add the entire code ...(more)OK, I managed to get the right reprojection error using the code inside findFundamentalMat as here and I changed part of the code that I posted previously. But I don't get why for every pairs of corresponding points, I get a quite big (14.61) mean residual value applying x'Fx=0. That's crappy. The coordinates should be normalized?