2011-08-11 57 views
3

給定3 x 3旋轉矩陣R和3 x 1平移矩陣T,我想知道如何將T和R矩陣與圖像相乘?使用OpenCV翻譯和旋轉圖像使用OpenCV

可以說的是IplImage IMG爲640 x 480

我想要做的就是R*(T*img)

我正在考慮使用cvGemm,但沒有奏效。

+2

答案是否有幫助,如果不讓我知道,我會盡力解釋,如果是的話:謝謝接受! Julien – jmartel

回答

4

您正在搜索的功能可能是warpPerspective():這是一個用例...

// Projection 2D -> 3D matrix 
     Mat A1 = (Mat_<double>(4,3) << 
      1, 0, -w/2, 
      0, 1, -h/2, 
      0, 0, 0, 
      0, 0, 1); 

// Rotation matrices around the X axis 
     Mat R = (Mat_<double>(4, 4) << 
      1,   0,   0, 0, 
      0, cos(alpha), -sin(alpha), 0, 
      0, sin(alpha), cos(alpha), 0, 
      0,   0,   0, 1); 

// Translation matrix on the Z axis 
     Mat T = (Mat_<double>(4, 4) << 
      1, 0, 0, 0, 
      0, 1, 0, 0, 
      0, 0, 1, dist, 
      0, 0, 0, 1); 

// Camera Intrisecs matrix 3D -> 2D 
     Mat A2 = (Mat_<double>(3,4) << 
      f, 0, w/2, 0, 
      0, f, h/2, 0, 
      0, 0, 1, 0); 

Mat transfo = A2 * (T * (R * A1)); 

Mat source; 
Mat destination; 

warpPerspective(source, destination, transfo, source.size(), INTER_CUBIC | WARP_INVERSE_MAP); 

我希望它可以幫助你,

朱利安

PS:我給出了從2D到3D的投影示例,但您可以直接使用transfo = T * R;

+0

我跟隨此鏈接http://jepsonsblog.blogspot.in/2012/11/rotation-in-3d-using-opencvs.html,但我不知道我需要給予什麼輸入。我嘗試了很少的數字,但無法成功。我的目的是沿y軸旋轉給定的圖像。 – 2vision2

+1

A1矩陣在這裏是錯誤的,它需要在第三行有另一個1。這個答案:https://stackoverflow.com/questions/17087446/how-to-calculate-perspective-transform-for-opencv-from-rotation-angles – 2017-06-11 21:21:46

+0

呃,對不起...我想你的方式可以工作以及只要您將相機(或圖像)從z = 0移回大z轉換... – 2017-06-11 21:38:02