2012-09-30 47 views
5

我從相同的兩個相機拍攝的兩幅圖像相距一定距離,捕捉相同的場景。我想計算兩臺相機之間的真實世界旋轉和平移。爲了達到這個目的,我首先提取了兩幅圖像的SIFT特徵並匹配它們。多視圖幾何

我現在有基本矩陣以及單應矩陣。但無法進一步進行,很多困惑。誰能幫我估計旋轉和翻譯在兩個攝像頭之間?

我使用OpenCV進行特徵提取和匹配單應計算。

回答

5

如果你有Homography,那麼你也有輪換。一旦你有單應性,很容易獲得旋轉和平移矩陣。

例如,如果正在使用的OpenCV C++:

param[in] H 
param[out] pose 
void cameraPoseFromHomography(const Mat& H, Mat& pose) 
{ 
    pose = Mat::eye(3, 4, CV_32FC1);  // 3x4 matrix, the camera pose 
    float norm1 = (float)norm(H.col(0)); 
    float norm2 = (float)norm(H.col(1)); 
    float tnorm = (norm1 + norm2)/2.0f; // Normalization value 

    Mat p1 = H.col(0);  // Pointer to first column of H 
    Mat p2 = pose.col(0); // Pointer to first column of pose (empty) 

    cv::normalize(p1, p2); // Normalize the rotation, and copies the column to pose 

    p1 = H.col(1);   // Pointer to second column of H 
    p2 = pose.col(1);  // Pointer to second column of pose (empty) 

    cv::normalize(p1, p2); // Normalize the rotation and copies the column to pose 

    p1 = pose.col(0); 
    p2 = pose.col(1); 

    Mat p3 = p1.cross(p2); // Computes the cross-product of p1 and p2 
    Mat c2 = pose.col(2); // Pointer to third column of pose 
    p3.copyTo(c2);  // Third column is the crossproduct of columns one and two 

    pose.col(3) = H.col(2)/tnorm; //vector t [R|t] is the last column of pose 
} 

此函數計算德照相機從單應性姿勢,其中轉動被含有。欲瞭解更多理論信息,請點擊這裏thread

+0

謝謝@Jav_Rock,你的回答幫助我估計姿勢。然而,對於任何圖像集,姿勢矩陣都是相同的,前三列形成一個單位矩陣,最後一列是空的。你有什麼想法嗎? – Aarambh

+0

我也通過使用warpAffine來確認單應矩陣,它正確地將圖像的視圖映射到另一個。 – Aarambh

+0

@ user1709317:'H'和'pose'需要具有相同的格式。如果更改'CV_32FC1'->'CV_64FC1',您可能會得到期望的結果。 – bjoernz