I am trying to get the fundamental Matrix for two matched point-sets using openCVs find findFundamentalMat(). The images are distorted, then I detect Keypoints and match those. I thought using undistortPoints would give me better results for the fundamental matrix(I know the intrinsic parameters of my camera), but after undistortPoints, findFundamentalMat gives strange results. First, in the resulting mask array, all points are considered inliers. Second, the error is very high. I compute the error like this:
vector<Point2f> points1Raw; //Raw points from Keypoints
vector<Point2f> points1; //Undistorted points
vector<Point2f> points2Raw;
vector<Point2f> points2;
for(int k=0; k<matches.size(); k++) {
points1Raw.push_back(keypoints1[matches[k].queryIdx].pt);
points2Raw.push_back(keypoints2[matches[k].trainIdx].pt);
};
undistortPoints(points1Raw, points1, cameraMatrixm, distCoeffsm);
undistortPoints(points2Raw, points2, cameraMatrixm, distCoeffsm);
vector<uchar> states;
Mat f = findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99, states);
//For all k matches
Mat p1(3, 1, CV_64F);
p1.at<double>(0, 0) = points1[k].x;
p1.at<double>(1, 0) = points1[k].y;
p1.at<double>(2, 0) = 1;
Mat p2(1, 3, CV_64F);
p2.at<double>(0, 0) = points2[k].x;
p2.at<double>(0, 1) = points2[k].y;
p2.at<double>(0, 2) = 1;
Mat res = abs(p2 * f * p1); // f computed matrix
if((bool)states[k]) //if match considered inlier (in my strange case all)
err = err + res.at<double>(0, 0); //accumulate errors
The total resulting error is like 100 to 1000 or even more. But by manually checking the matches before computing the fundamental matrix, most of them seem right. What am I doing wrong? :/
How many points do you have? To be counted as inlier, an error up to (in your case) 3 pixels is allowed,... so if you have several hundred points, it's clear that the cumulated error is big.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With