Translating and Rotating an Image in 3D using OpenCV

醉酒当歌 提交于 2019-12-21 03:13:10

问题


Given a 3 x 3 rotation matrix,R, and a 3 x 1 translation matrix,T, I am wondering how to multiply the T and R matrices to an image?

Lets say the Iplimage img is 640 x 480.

What I want to do is R*(T*img).

I was thinking of using cvGemm, but that didn't work.


回答1:


The function you are searching for is probably warpPerspective() : this is a use case...

// 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);

I hope it could help you,

Julien

PS : I gave the example with a projection from 2D to 3D but you can use directly transfo = T* R;



来源:https://stackoverflow.com/questions/7019407/translating-and-rotating-an-image-in-3d-using-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!