findFundamentalMatrix and SiftGPU

asked 2018-02-19 07:22:55 -0500

KirbX gravatar image

updated 2018-02-19 08:25:17 -0500

Hi all!
I'm trying to find the Fundamental Matrix with the findFundamentalMat function. I generate keypoints (x,y) with Sift-GPU.

The matrix I generate is

    0,    0,   0.6   
    0,    0,  -0.3  
 -0.4,  0.2,     0

(Can it be even possible that my diagonal is composed of 0's?) If I use a std::vector<uchar> to look at outliers and inliers, it gives me only 0's (outliers), even if I change the used algorithm.

What I give to the function is 2 vectors composed with (x,y) of all correspondance. (x,y are for example (540, 355)).

/*
... Use siftgpu 
*/
std::vector<int(*)[2]> match_bufs; //Contain (x,y) from the 2 images that are paired
SiftGPU::SiftKeypoint & key1 = keys[match_bufs[i][0]];
SiftGPU::SiftKeypoint & key2 = keys[match_bufs[i][1]];


float x_l, y_l, x_r, y_r; //(x,y of left and right images)
x_l = key1.x; y_l = key1.y;
x_r = key2.x; y_r = key2.y;

vec1.push_back(x_l); vec1.push_back(y_l);
vec2.push_back(x_r); vec2.push_back(y_r); 
std::vector<uchar> results;
int size = vec1.size();
results.resize(size);

std::vector<cv::Point2f> points1; //corrected
std::vector<cv::Point2f> points2;
for (int i = 0; i < size; i+=2) {
    points1.push_back(cv::Point2f(vec1[i], vec1[i + 1]));
    points2.push_back(cv::Point2f(vec2[i], vec2[i + 1]));
}

cv::Mat fund = cv::findFundamentalMat(points1, points2, CV_FM_RANSAC, 3, 0.99, results);

I tried to normalize them to make them between [0,1] but it doesn't work neither.
Do I am missing something? Is there something I don't understand in the use of this function? /:

Thanks a lot!

edit retag flag offensive close merge delete

Comments

How many points do you use to estimate the fundamental matrix?

In your code, it should be for (int i = 0; i < size; i+=2) { as you store in vec1 x and y coordinates sequentially.

Eduardo gravatar imageEduardo ( 2018-02-19 08:05:18 -0500 )edit

Obivously yes, you're right... I'm using 346 points actually. Is that too much?

KirbX gravatar imageKirbX ( 2018-02-19 08:09:25 -0500 )edit

Ok, i corrected another wrong thing : std::vector<cv::Point2f> points1,points2; I gave them an initial size at the beggining so when i pushed back, i was only going nowhere, cause my size first elements were 0, now the matrix seems to be better, but I have still all the 0's

KirbX gravatar imageKirbX ( 2018-02-19 08:26:57 -0500 )edit