一些有用的鏈接: http://urbanar.blogspot.it/2011/04/from-homography-to-opengl-modelview.html
和 http://cvrr.ucsd.edu/publications/2008/MurphyChutorian_Trivedi_CVGPU08.pdf
Firt當你在K分解你的P矩陣,R,T,其中k是內在的矩陣,R,T相對姿態旋轉和翻譯,那麼就可以生成相應的OpenGL矩陣如下(我的解決辦法是在C++中,但你可以把它理解背後的邏輯):
Eigen::Matrix4d convertIntrinsicToOpenGLProjection(const Eigen::Matrix3d &K,double x0,double y0,double width,double height,double znear,double zfar)
{
double depth = zfar - znear;
double q = -(zfar + znear)/depth;
double qn = -2.0 * (zfar * znear)/depth;
Eigen::Matrix4d proj;
proj << 2*K(0,0)/width, -2*K(0,1)/width, (-2*K(0,2)+width+2*x0)/width, 0 ,
0, -2*K(1,1)/height,(-2*K(1,2)+height+2*y0)/height, 0,
0,0,q,qn,
0,0,-1,0;
return proj;
}
Affine3d convertExtrinsicToOpenGLModelView(const Matrix3d &R, const Vector3d &t)
{
Affine3d MV;
MV.linear().matrix() << R;
MV.translation() << t;
AngleAxis<double> adapter(M_PI,Eigen::Vector3d(1,0,0));
MV = MV*adapter;
return MV.inverse();
}
// Decompose P in k,R,t with any DLT direct linear transform procedure or Zhang method
Eigen::Matrix3d K; //intrinsic calibration matrix
K << 49.30423 , 0.00000 , 387.13187,
0.00000 , 26.81592 , 295.07170,
0.00000 , 0.00000 , 1.00000 ;
int projAreaWidth = 684; //related to the size of your screen
int projAreaHeight = 608;
double x0=0,y0=0;
double zfar=0.1;
double znear=2000;
Matrix4d P = convertIntrinsicToOpenGLProjection(K, x0, y0, width, height, znear, zfar);
Affine3d MV = convertExtrinsicToOpenGLModelView(R, t);
glPushMatrix();
glLoadMatrixd(P.data());
glMultMatrixd(MV.data());
//draw your object
glPopMatrix();
讓我知道這對你是否合理。
爲什麼?如果您的眼睛/相機具有與投影機完全相同的位置和方向,看起來結果只會看起來不錯。只要你的眼睛/相機離軸,投影版本會越來越差。 – genpfault