使用 OpenCV 平移和旋转 3D 图像 [英] Translating and Rotating an Image in 3D using OpenCV
本文介绍了使用 OpenCV 平移和旋转 3D 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个 3 x 3 的旋转矩阵 R 和一个 3 x 1 的平移矩阵 T,我想知道如何将 T 和 R 矩阵与图像相乘?
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?
假设 Iplimage img 为 640 x 480.
Lets say the Iplimage img is 640 x 480.
我想做的是R*(T*img)
.
我正在考虑使用 cvGemm,但没有成功.
I was thinking of using cvGemm, but that didn't work.
推荐答案
您正在搜索的函数可能是 warpPerspective() :这是一个用例...
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);
希望对你有帮助
朱利安
PS:我给出的示例是从 2D 到 3D 的投影,但您可以直接使用 transfo = T* R;
PS : I gave the example with a projection from 2D to 3D but you can use directly transfo = T* R;
这篇关于使用 OpenCV 平移和旋转 3D 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文