2011-08-24 150 views
3

我試圖使用普通的LCD投影機將圖像照到簡單的3D形狀上,但以可重複的方式進行。3D投影映射

我需要什麼: 我簡單的例子是,我放置一個立方體桌子上,將安裝在三腳架上一段距離投影儀,測量兩者之間的距離/方向(使用GOM photogammetry產品,http://www.capture3d.com/products-TRITOP.html)打開一個與立方體形狀完全相同(尺寸非常精確)的現有obj(多邊形)模型,但使用一些「花哨」着色,然後將多邊形模型投影到LCD投影儀。

我做了什麼: 花了一個月的時間試圖確定我的投影機的內在/外在常量 - 相機對,焦距,原理點,失真常數......我想我擁有它們。 (http://code.google.com/p/procamcalib/)

我找到/修改了代碼來打開我的obj文件。

我不知道如何處理投影機的這些內在/外在常量。

我使用的OpenGL/OpenCV的...

+1

爲什麼?如果您的眼睛/相機具有與投影機完全相同的位置和方向,看起來結果只會看起來不錯。只要你的眼睛/相機離軸,投影版本會越來越差。 – genpfault

回答

0

描述here您可以從它的焦距計算攝像機視場。一旦你有了視野,你可以使用gluPerspective()(或者do the calculation yourself - 見9.085)來設置透視矩陣。您顯然需要根據投影機和對象的位置來更改模型視圖矩陣。我不知道你有什麼失真數據,但你也可能需要考慮這一點。

1

一些有用的鏈接: 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(); 

讓我知道這對你是否合理。