2012-07-28 189 views
2

我有一個從函數Core.Rodrigues在opencv旋轉矩陣。我想通過這個旋轉矩陣來旋轉位於(0,0,1)處圍繞原點的點。我如何做到這一點,以獲得重點的新位置?使用旋轉矩陣opencv

Mat rmat= new Mat(); 
    Calib3d.Rodrigues(rvec, rmat); //rvec is the rotation vector from solvepnp 
    double[] p= {0, 0, 1}; 
    Scalar scalar= new Scalar(p); 
    Mat point= new Mat(1, 3, CvType.CV_64F, scalar); 
    Mat newpoint= new Mat(); 
    Mat empty= new Mat(); 
    Core.gemm(point, rmat, 1, empty, 0, newpoint); 

newpoint有0,0,對於結果0,當我知道這是錯誤的

任何幫助,將不勝感激。

回答

3

旋轉關於原點的點的方法是將其與旋轉矩陣預乘。我不熟悉Core.gemm。這是一個更透明的做法。

Mat rmat= new Mat(); 
Calib3d.Rodrigues(rvec, rmat); //rvec is the rotation vector from solvepnp 
Matx33f rotation_matrix = rmat; 
Matx31f original_point(0,0,1); 
Matx31f rotated_point = rotation_matrix*original_point; 

這應該更容易調試。檢查存儲在rotation_matrix中的值,確保它們已初始化爲合理值(Matx的內容可在調試器中看到)。您可以查看這些值並自己進行乘法運算以仔細檢查您是否喜歡。這個過程應該完全透明。

0

在你的代碼中,你是否巧合定義了你的點p,然後又不再使用它?另外,你用矩陣點的值創建一個標量對象,然後用該標量設置點的值?也許這是你錯誤的根源。

+0

不,在寫這篇文章時,我改變了變量名,使讀者更容易理解,並且我犯了一個錯誤。實際的代碼現在與上面的代碼相同。對不起,這個錯誤。 – Isaac 2012-07-29 20:56:08