1. 程式人生 > 其它 >多視幾何_計算兩幅影象之間的基礎矩陣F和一副影象上的點在另一福影象上的極線L

多視幾何_計算兩幅影象之間的基礎矩陣F和一副影象上的點在另一福影象上的極線L

技術標籤:三維重建SLAM

功能說明:

  • 輸入:兩幀影象的相對變換Tji =(R,t) (從影象i變換到影象j), 相機的內參K (假設兩幅影象使用的相機是同一個), 輸入影象i中的點m
  • 輸出:計算影象i的m點, 在影象j上的極線l'm= (a,b,c), (則影象j上的極線方程為 ax + by +c = 0)

圖示:

實現:


def  calculate_epipolar_line (K, Tji, m):
    """
   calculate the epipolar line for point m
    Args:
        K (numpy, (3,3) ):  the intrinsic parameter of camera0 and camera1
        Tji (numpy, 4x4): the transformation from frame i(camera0) to  frame j(camera1)
        m (numpy, (2,) ): (x,y) point u in frame i(camera0)

    Returns:
        L(numpy, (3,1) ): the epipolar line of m in frame j
    """
    R =Tji[0:3,0:3]
    t = Tji[0:3, 3].reshape([3,1])
    MatK = mat(K)
    MatR = mat(R)
    
    # the epipolar point in frame i
    e = MatK * MatR.T * t   # shape: (3,1) #check ok
    # the antisymmetric matrix of e
    ex = mat(np.array([ [0, -e[2,0], e[1,0]],
                                            [e[2,0], 0, -e[0,0]],
                                            [-e[1,0], e[0,0], 0]]))
    # the fundamental matrix
    F = MatK.T.I * MatR * MatK.T * ex
    assert (matrix_rank(F) == 2) 

    m_h = np.array([[m[0]],[m[1]],[1]])
    L = F * m_h

    return L