Vieinco

09-01-2010, 06:07 AM

I try to reconstruct some 3d scene from real world.

From camera calibration by chessboard i had: Matrix(R|T) - transformation matrix (rotation|translation), and internal camera paramenters (focal, cx,cy) - matrix K. And now i'll try to reconstruct chessboard in OpenGL.

Step #1: i perfomed projection calculation by matrix operation (using pure C++)

1. M = K*(R|T)

2. V = M*ObjectModelPoint

3. ScreenX = v.x/v.z; ScreenY = v.y/v.z;

4. Draw point on ScreenX, ScreenY coordinates.

And i had correct recunstruction (visual prove)...

Step #2: I try to translate visualization process via OpenGL.

Step #2.1 If i try to perform some calculation sequence like OpenGL pipeline (according with documentation), i would have code like this

1. (R|T)*ObjectModelPoint = eyePoint

2. ProjectionMatrix * eyePoint = clipPoint

// <= glFrustum( cx, cx - w, cy, cy - h, focal, 3*focal);

// glGetFloatv(GL_PROJECTION_MATRIX, ProjectionMatrix); to get ProjectionMatrix

3. clip all points out of -1,1

4. ndcPoint = clipPoint / clipPoint.w

5. ViewPoint = ViewportMatrix * ndcPoint

// ViewportMatrix - matrix equevalent to glViewport operation

6. draw point at ViewPoint.x, ViewPoint.y

And I have correct visualization (and check all transformation formula manualy)

Step #2.2(!!!) I try to use OpenGL pipeline

1. glViewport(0, 0, w, h);

2. glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glFrustum( cx , cx - w, cy, cy - h, z, 3*z);

// glGetFloatv return the same matrix like ProjectionMatrix in step 2.1

3. glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt( 0.0, 0.0, -focal, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0);

glMultMatrixf(Matrix(R|T));

4. set ObjectModelPoints // glBegin(GL_QUADS); glVertex3d(....)....

BUT in this step i have incorrect visualization :sick:

Position and orientation of model looks like a correct (if a zoom it), but scale factor is toooooo smaaalll (i have aproximatly 5 on 5 pixels object =)) )

Where I fail?! or may be OpenGL pipeline do some also?....

// I can give sources of test project

From camera calibration by chessboard i had: Matrix(R|T) - transformation matrix (rotation|translation), and internal camera paramenters (focal, cx,cy) - matrix K. And now i'll try to reconstruct chessboard in OpenGL.

Step #1: i perfomed projection calculation by matrix operation (using pure C++)

1. M = K*(R|T)

2. V = M*ObjectModelPoint

3. ScreenX = v.x/v.z; ScreenY = v.y/v.z;

4. Draw point on ScreenX, ScreenY coordinates.

And i had correct recunstruction (visual prove)...

Step #2: I try to translate visualization process via OpenGL.

Step #2.1 If i try to perform some calculation sequence like OpenGL pipeline (according with documentation), i would have code like this

1. (R|T)*ObjectModelPoint = eyePoint

2. ProjectionMatrix * eyePoint = clipPoint

// <= glFrustum( cx, cx - w, cy, cy - h, focal, 3*focal);

// glGetFloatv(GL_PROJECTION_MATRIX, ProjectionMatrix); to get ProjectionMatrix

3. clip all points out of -1,1

4. ndcPoint = clipPoint / clipPoint.w

5. ViewPoint = ViewportMatrix * ndcPoint

// ViewportMatrix - matrix equevalent to glViewport operation

6. draw point at ViewPoint.x, ViewPoint.y

And I have correct visualization (and check all transformation formula manualy)

Step #2.2(!!!) I try to use OpenGL pipeline

1. glViewport(0, 0, w, h);

2. glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glFrustum( cx , cx - w, cy, cy - h, z, 3*z);

// glGetFloatv return the same matrix like ProjectionMatrix in step 2.1

3. glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt( 0.0, 0.0, -focal, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0);

glMultMatrixf(Matrix(R|T));

4. set ObjectModelPoints // glBegin(GL_QUADS); glVertex3d(....)....

BUT in this step i have incorrect visualization :sick:

Position and orientation of model looks like a correct (if a zoom it), but scale factor is toooooo smaaalll (i have aproximatly 5 on 5 pixels object =)) )

Where I fail?! or may be OpenGL pipeline do some also?....

// I can give sources of test project