簡體   English   中英

基本矩陣的分解會導致錯誤的旋轉和平移

[英]Decomposition of essential matrix leads to wrong rotation and translation

我正在做一些SfM,從基本矩陣中獲取R和T時遇到麻煩。

這是我在源代碼中正在做的事情:

Mat fundamental = Calib3d.findFundamentalMat(object_left, object_right);
Mat E = new Mat();

Core.multiply(cameraMatrix.t(), fundamental, E); // cameraMatrix.t()*fundamental*cameraMatrix;
Core.multiply(E, cameraMatrix, E);

Mat R = new Mat();
Mat.zeros(3, 3, CvType.CV_64FC1).copyTo(R);

Mat T = new Mat();

calculateRT(E, R, T);

where `calculateRT` is defined as follows:

private void calculateRT(Mat E, Mat R, Mat T) {

    /*
     * //-- Step 6: calculate Rotation Matrix and Translation Vector
        Matx34d P;
        //decompose E 
        SVD svd(E,SVD::MODIFY_A);
        Mat svd_u = svd.u;
        Mat svd_vt = svd.vt;
        Mat svd_w = svd.w;
        Matx33d W(0,-1,0,1,0,0,0,0,1);//HZ 9.13
        Mat_<double> R = svd_u * Mat(W) * svd_vt; //
        Mat_<double> T = svd_u.col(2); //u3

        if (!CheckCoherentRotation (R)) {
            std::cout<<"resulting rotation is not coherent\n";
            return 0;
        }
     */
    Mat w = new Mat();
    Mat u = new Mat();
    Mat vt = new Mat();

    Core.SVDecomp(E, w, u, vt, Core.DECOMP_SVD); // Maybe use flags
    Mat W = new Mat(new Size(3,3), CvType.CV_64FC1);
    W.put(0, 0, W_Values);

    Core.multiply(u, W, R);
    Core.multiply(R, vt, R);

    T = u.col(2);
}

這是計算后和計算過程中所有矩陣的結果。

    Number matches: 10299
    Number of good matches: 590
    Number of obj_points left: 590.0


         CameraMatrix: 
                        [1133.601684570312,         0,             639.5;
                               0 ,          1133.601684570312,     383.5;
                               0,                   0,               1]


       DistortionCoeff: [0.06604336202144623; 0.21129509806633; 0; 0; -1.206771731376648]


    Fundamental: 
    [4.209958176688844e-08, -8.477216249742946e-08, 9.132798068178793e-05;
    3.165719895008366e-07, 6.437858397735847e-07, -0.0006976204595236443;
    0.0004532506630569588, -0.0009224427024602799, 1]

    Essential: 
    [0.05410018455525099, 0, 0;
    0, 0.8272987826496967, 0;
    0, 0, 1]

    U: (SVD)
    [0, 0, 1;
     0, 0.9999999999999999, 0;
     1, 0, 0]

    W: (SVD) 
    [1; 0.8272987826496967; 0.05410018455525099]

    vt: (SVD)
    [0, 0, 1;
     0, 1, 0;
     1, 0, 0]


    R: 
    [0, 0, 0;
     0, 0, 0;
     0, 0, 0]

    T: 
    [1; 0; 0]

為了完成此操作,這里是我使用的圖像: leftright

在計算FeaturePoints等之前,我對圖像進行了不失真處理。

有人可以指出哪里出了問題或我做錯了什么嗎?

編輯:問題我的基本矩陣是否有可能等於我在校准情況下的基本矩陣,哈特利和齊瑟曼說:

“ 11.7.3校准情況:在校准攝像機的情況下,可以使用歸一化的圖像坐標,並且計算基本矩陣E而不是基本矩陣”

我發現了錯誤。 此代碼未執行正確的矩陣乘法。

  Mat E = new Mat();
  Core.multiply(cameraMatrix.t(),fundamental, E); 
  Core.multiply(E, cameraMatrix, E);

我將其更改為

  Core.gemm(cameraMatrix.t(), fundamental, 1, cameraMatrix, 1, E);

現在正在執行正確的矩陣乘法。 據我從文檔中得到的信息,Core.multiply正在對每個元素進行乘法運算。 不是row * col的點積。

首先,除非您通過明確考慮相機矩陣的逆來計算基本矩陣,否則您將不在校准情況下,因此您估計的基本矩陣不是必不可少的矩陣。 這也很容易測試:您只需要對基本矩陣進行特征分解,然后查看兩個非零特征值是否相等(請參見Hartley&Zisserman書中的第9.6.1節)。

其次,基本矩陣和基本矩陣都為兩台攝像機定義,如果僅考慮一台攝像機,則沒有意義。 如果你有兩個攝像頭,與相應的矩陣K 1和K 2,則可以得到基本矩陣E 12,給出(其在I 1映射點線I 2),使用下面的公式基本矩陣F 12 (請參見Hartley&Zisserman的書中的公式9.12):

E 12 = K 2 T。 F 12 1

在您的情況下,兩邊都使用K 2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM