Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the fundamental matrix for stereo vision

I'm trying to write some code that will calculate the fundamental matrix to determine the relationship between stereo images. I started with the Hartley and Zisserman book that most people recommend, but it didn't have any practical examples and the sample code for it was in MATLAB which I don't have. I then switched to An introduction to 3D Computer Vision Techniques and Algorithms which is more practical and has actual examples in it. I implemented the recommended 8-point algorithm using Python and numpy, but I'm having trouble verifying the validity of it.

I'm using the dataset listed on page 48 (use that link above to see a Google Books excerpt) of that book. When I normalize the points, I get the same results as that book. However, when I use numpy's SVD function to calculate the fundamental matrix, I get the following value for F:

[[-0.01851684 -0.21631176 -0.67036356]
 [ 0.2605251  -0.01023853  0.14234079]
 [ 0.63748775 -0.09404508 -0.00220713]]

This matrix satisfies the equation p_R^ * F * p_L = 0 so it seems correct. However, it is very different from the matrix calculated in the book. I tried to double check the answer using OpenCV's cv.FindFundamentalMat() and I got a third answer:

[[  22.98129082  271.46453857  853.74273682]
 [-334.1673584    -4.84123087 -175.99523926]
 [-809.88891602  125.99833679    1.        ]]

I'm not how those other two matrices are calculated, but I can't find any examples of fundamental matrix calculation on the web to verify my implementation of the 8-point algorithm. The fact that my implementation returns a value that satisfies the equation gives me confidence, but I'm worried that I did something silly which is why I can't match the results in the book or by OpenCV.

like image 329
SigmaXiPi Avatar asked Apr 04 '11 01:04

SigmaXiPi


People also ask

How do you estimate the fundamental matrix?

Randomly select 8 pairs of points from matchedPoints1 and matchedPoints2 . Use the selected 8 points to compute a fundamental matrix, f, by using the normalized 8-point algorithm. Compute the fitness of f for all points in matchedPoints1 and matchedPoints2 . If the fitness of f is better than F, replace F with f.

What is the fundamental matrix stereo vision?

The fundamental matrix is a relationship between any two images of the same scene that constrains where the projection of points from the scene can occur in both images.

How do you calculate camera matrix?

The camera projection matrix and the fundamental matrix can each be estimated using point correspondences. To estimate the projection matrix—intrinsic and extrinsic camera calibration—the input is corresponding 3d and 2d points. To estimate the fundamental matrix the input is corresponding 2d points across two images.

How do you find the fundamental matrix of an epipolar line?

Similar to the Essential matrix, we can compute the epipolar lines l = FT p and l = Fp from just the Fundamental matrix and the corresponding points.


1 Answers

Note that the Fundamental matrix is defined up to a constant factor (you can verify that quite easily, by checking the epipolar constraint). Try multiplying the OpenCV matrix with -8.0574e-04 and you'll see that the two matrices are quite similar in the end :-)

Thus, your result is probably fine. The slight difference between the results is probably due to the fact that OpenCV employs a different (probably more robust) approach than the 8-point algorithm.

like image 151
ssegvic Avatar answered Sep 29 '22 20:09

ssegvic