I try to reconstruct some 3d scene from real world.
From camera calibration by chessboard i had: Matrixb[/b] - 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++)
- M = K*(R|T)
- V = M*ObjectModelPoint
- ScreenX = v.x/v.z; ScreenY = v.y/v.z;
- 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
- (R|T)*ObjectModelPoint = eyePoint
- ProjectionMatrix * eyePoint = clipPoint
// <= glFrustum( cx, cx - w, cy, cy - h, focal, 3*focal);
// glGetFloatv(GL_PROJECTION_MATRIX, ProjectionMatrix); to get ProjectionMatrix - clip all points out of -1,1
- ndcPoint = clipPoint / clipPoint.w
- ViewPoint = ViewportMatrix * ndcPoint
// ViewportMatrix - matrix equevalent to glViewport operation - 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
-
glViewport(0, 0, w, h);
-
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 -
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)); -
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