使用 OpenCV 转换和旋转 3D 图像

Ser*_*yro 5 opencv rotation translate-animation

给定一个 3 x 3 旋转矩阵 R 和一个 3 x 1 平移矩阵 T,我想知道如何将 T 和 R 矩阵乘以图像?

假设 Iplimage img 是 640 x 480。

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

我正在考虑使用 cvGemm,但这没有用。

jma*_*tel 7

您正在搜索的功能可能是 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);
Run Code Online (Sandbox Code Playgroud)

希望可以帮到你

于连

PS:我举了一个从 2D 到 3D 的投影的例子,但你可以直接使用 transfo = T* R;

  • A1 矩阵在这里是错误的,它需要在第三行再有一个 1。这个答案:/sf/ask/1196121251/ (2认同)