如何计算立体视觉的基本矩阵
我正在尝试编写一些代码来计算基本矩阵以确定立体图像之间的关系。我从大多数人推荐的 Hartley 和 Zisserman 书开始,但它没有任何实际示例,并且示例代码是在 MATLAB 中,而我没有。然后我切换到3D 计算机视觉技术和算法简介 比较实用,里面有实际例子。我使用 Python 和 numpy 实现了推荐的 8 点算法,但在验证其有效性时遇到了困难。
我正在使用该书第 48 页上列出的数据集(使用上面的链接查看 Google 图书摘录)。当我对点进行标准化时,我得到了与那本书相同的结果。然而,当我使用 numpy 的 SVD 函数计算基本矩阵时,我得到以下 F 值:
[[-0.01851684 -0.21631176 -0.67036356]
[ 0.2605251 -0.01023853 0.14234079]
[ 0.63748775 -0.09404508 -0.00220713]]
该矩阵满足方程 p_R^ * F * p_L = 0 因此它看起来是正确的。不过和书上计算的矩阵有很大不同。我尝试使用 OpenCV 的 cv.FindFundamentalMat() 仔细检查答案,得到了第三个答案:
[[ 22.98129082 271.46453857 853.74273682]
[-334.1673584 -4.84123087 -175.99523926]
[-809.88891602 125.99833679 1. ]]
我不是如何计算其他两个矩阵的,但我在网络上找不到任何基本矩阵计算的示例来验证我的8点算法的实现。我的实现返回一个满足方程的值这一事实给了我信心,但我担心我做了一些愚蠢的事情,这就是为什么我无法匹配书中或 OpenCV 中的结果。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,基本矩阵被定义为一个常数因子(您可以通过检查对极约束来轻松验证这一点)。尝试将 OpenCV 矩阵与 -8.0574e-04 相乘,您会发现这两个矩阵最终非常相似:-)
因此,您的结果可能很好。结果之间的细微差异可能是由于 OpenCV 采用了与 8 点算法不同(可能更稳健)的方法。
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.