Opencv:从R和T计算基本矩阵 [英] Opencv: Computing fundamental matrix from R and T

查看:456
本文介绍了Opencv:从R和T计算基本矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算立体相机的对极线。
我既知道相机的内在矩阵,也知道R和T。
我试图按照《学习Opencv》和Wikipedia所述计算基本矩阵。





其中[t] x



因此





我尝试使用python实现此功能,然后使用opencv函数,T 1 ],[T 2 ,0,-T [0]],[-T 1 ,T [0],0]])



现在,Epilines会聚在子极上。

解决方案

哼,您的F矩阵似乎是错误的-是杜松子酒,排名比2更接近3。
从您的数据中,我得到:

  octave:9> tx = [0 -T(3)T(2)
> T(3)0 -T(1)
> -T(2)T(1)0]
tx =

0.000000 0.028545 0.041492
-0.028545 0.000000 -0.000165
-0.041492 0.000165 0.000000

八度:11> E = R * tx
E =

-2.1792e-04 2.8546e-02 4.1491e-02
-4.8255e-02 4.6088e-05 -2.1160e-04
1.4415e-02 1.1148e-04 2.4526e-04

八度:12> F = inv(M1')* E * inv(M2)
F =

-3.6731e-10 4.8113e-08 2.4320e-05
-8.1333e-08 7.7681e-11 6.7289e-05
7.0206e-05 -3.7128e-05 -7.6583e-02

八度:14> rank(F)
ans = 2

这似乎更有意义。您可以在绘图代码中尝试使用该F矩阵吗?


I want to compute the epipolar lines of a stereo camera. I know both camera intrinsics matrix as well as R and T. I tried to compute the essential matrix as told in Learning Opencv book and wikipedia.

where [t]x is the matrix representation of the cross product with t.

so

I tried to implement this with python and then use the opencv function cv2.computeCorrespondEpilines to compute the epilines.

The problem is that the lines I get don't converge in a point as they should... I guess I must have a problem computing F.

This is the relevant pice of code:

 T #Contains translation vector
 R #Rotation matrix
 S=np.mat([[0,-T[2],T[1]],[T[2],0,-T[1]],[-T[1],T[0],0]])
 E=np.mat(R)*S

 M1=np.mat(self.getCameraMatrix(cam1))
 M1_inv=np.linalg.inv(M1)
 M2=np.mat(self.getCameraMatrix(cam2))
 M2_inv=np.linalg.inv(M2)

 F=(M2_inv.T)*E*M1_inv

The matrices are:

M1=[[ 776.21275864    0.          773.70733324]
 [   0.          776.21275864  627.82872456]
 [   0.            0.            1.        ]]

M2=[[ 764.35675708    0.          831.26052677]
 [   0.          764.35675708  611.85363745]
 [   0.            0.            1.        ]]

R=[[ 0.9999902   0.00322032  0.00303674]
 [-0.00387935  0.30727176  0.9516139 ]
 [ 0.0021314  -0.95161636  0.30728124]]

T=[ 0.0001648   0.04149158 -0.02854541]

The ouput F I get it's something like:

F=[[  4.75910592e-07   6.28777619e-08  -2.78886982e-04]
 [ -4.66942275e-08  -7.62837993e-08  -7.34825205e-04]
 [ -8.86965149e-04  -6.86717269e-04   1.40633035e+00]]

EDITED: The cross multiplication matrix was wrong, it has to be: S=np.mat([[0,-T2,T1],[T2,0,-T[0]],[-T1,T[0],0]])

The epilines converge now at the epipole.

解决方案

Hum, your F matrix seems wrong - to begin with, the rank is closer to 3 than 2. From your data I get:

octave:9> tx = [ 0 -T(3) T(2)
> T(3) 0 -T(1)
> -T(2) T(1) 0]
tx =

   0.000000   0.028545   0.041492
  -0.028545   0.000000  -0.000165
  -0.041492   0.000165   0.000000

octave:11> E= R* tx
E =

  -2.1792e-04   2.8546e-02   4.1491e-02
  -4.8255e-02   4.6088e-05  -2.1160e-04
   1.4415e-02   1.1148e-04   2.4526e-04

octave:12> F=inv(M1')*E*inv(M2)
F =

  -3.6731e-10   4.8113e-08   2.4320e-05
  -8.1333e-08   7.7681e-11   6.7289e-05
   7.0206e-05  -3.7128e-05  -7.6583e-02

octave:14> rank(F)
ans =  2

Which seems to make more sense. Can you try that F matrix in your plotting code?

这篇关于Opencv:从R和T计算基本矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆