我有一个旋转平移矩阵 [R T](3x4)。
在OpenCV中,是否有执行由[R T]描述的旋转平移的功能?
我有一个旋转平移矩阵 [R T](3x4)。
在OpenCV中,是否有执行由[R T]描述的旋转平移的功能?
transform = [B]*inverse([A])
概念上,您需要做的是将第一张图像的像素投影到三维空间中的几何解释中,然后通过上述变换在三维空间中转换这些像素,最后使用相机矩阵将它们投影回一个新的二维图像。这些步骤需要组合成一个单独的3x3矩阵。
cv::Matx33f convert_3x4_to_3x3(cv::Matx34f pose, cv::Matx33f camera_mat, float zpos)
{
//converted condenses the 3x4 matrix which transforms a point in world space
//to a 3x3 matrix which transforms a point in world space. Instead of
//multiplying pose by a 4x1 3d homogeneous vector, by specifying that the
//incoming 3d vectors will ALWAYS have a z coordinate of zpos, one can instead
//multiply converted by a homogeneous 2d vector and get the same output for x and y.
cv::Matx33f converted(pose(0,0),pose(0,1),pose(0,2)*zpos+pose(0,3),
pose(1,0),pose(1,1),pose(1,2)*zpos+pose(1,3),
pose(2,0),pose(2,1),pose(2,2)*zpos+pose(2,3));
//This matrix will take a homogeneous 2d coordinate and "projects" it onto a
//flat plane at zpos. The x and y components of the incoming homogeneous 2d
//coordinate will be correct, the z component is dropped.
cv::Matx33f projected(1,0,0,
0,1,0,
0,0,zpos);
projected = projected*camera_mat.inv();
//now we have the pieces. A matrix which can take an incoming 2d point, and
//convert it into a pseudo 3d point (x and y correspond to 3d, z is unused)
//and a matrix which can take our pseudo 3d point and transform it correctly.
//Now we just need to turn our transformed pseudo 3d point back into a 2d point
//in our new image, to do that simply multiply by the camera matrix.
return camera_mat*converted*projected;
}
这可能比你想要的答案更复杂,但我希望它能让你了解你所问的问题。这可能非常令人困惑,我快速地浏览了一些部分,如有需要,请随时要求澄清。如果您需要不假定初始图像出现旋转的解决方案,请告诉我,我只是不想使它比必要的更加复杂。