PDA

View Full Version : how do we get GL_VIEWPORT_MATRIX



santhosh2708
12-30-2002, 04:58 AM
Hi,
I am doing Image Based Rendering and want the camera calibration. We chose OpenGL, but getting the final Camera Matrix in the form

[x y z] = K[R |t] [X Y Z]'

has become difficult.

{Assuming a simple pin-hole camera model,
K is a 3x3 camera internal parameter matrix. R,t are Rotation Translation values}


As in GL gives GL_MODELVIEW_MATRIX
and GL_PROJECTION_MATRIX only
but now a matrix form viewport tranformation.

[ w/2 0 w/2 ]
[ 0 h/2 h/2 ]
[ 0 0 0 ]

The above matrix did not give the same
points.

please let me know how to get this viewport transform in a matrix form.

[screen_pt] = [vpt] [projective_tran] [modelview_tran] [world_point]
^^^^

regards
--
Santhosh
santhosh@gdit.iiit.net

cass
12-30-2002, 07:28 AM
Pixels are sampled at the pixel center.

If you want to pretend they're sampled at
the pixel corner, you'll need to add an extra (.5, .5) bias to your projection matrix...

santhosh2708
12-30-2002, 07:38 AM
Can I get a viewport transformation matrix
that will complete the set of matrices
involved in a 3D->2D mapping

cass
12-30-2002, 10:14 AM
I don't understand the question.

The mapping from object space to window space is well defined. You just need to specify the appropriate matrices to use input coordinates of your choice.

What *exactly* are you trying to do?

Cass

santhosh2708
12-30-2002, 12:30 PM
I wanted the [vpt] transform mentioned in the first post
yes, all the matrices are well defined like
GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX
but GL - does not maintain a GL_VIEWPORT_MATRIX which I am looking for
This is because I wanted all transforms in matrix form only

roffe
12-31-2002, 12:43 AM
gl doesn't store any GL_VIEWPORT_MATRIX matrix, you have to get the viewport using glGet(GL_VIEWPORT). I guess this is because the viewport transform is a simple affine transform.

"[screen_pt] = [vpt] [projective_tran] [modelview_tran] [world_point]"

You don't say what kind of projection you are using. If perspective this is not possible because, well its perspective, you divide with your depth coordinate before the viewport transform.

"The above matrix did not give the same points."

The viewport transformation includes translation, you need to use homogeneous coordinates.

A viewport matrix could be created like below in homogeneous coords, where
x and y are bottom left window coordinates.

w/2 0 0 (x + w/2)
0 h/2 0 (y + h/2)
0 0 1 0
0 0 0 1

santhosh2708
12-31-2002, 06:04 AM
Thanks
This worked
[vpt] as

| w/2___0___0_w/2 |
| __0_h/2___0_h/2 |
| __0___0___1___0 |
| __0___0___0___1 |

yes, my projection matrix represents perspective projection and the 3D is point need to be represented as [ X Y Z 1 ]' in this case.

so that
I get
[x y z w]' = [vpt][perspective][modelview][X Y Z 1]'

Then GL converts to 2D point as
[x/w y/w z/w] and z/w is discretized to the depth buffer

Unfortunately this image based rendering arithmetic doesnot assume a homogenous coord. system.

But can the above situation can be approximated as a simple pin-hole perspective camera model with

[x y z] = K(3x3) * [R t] (3x4) * [ X Y Z 1 ]'

This is because I need to embed such a K in implementing a ImageBasedRendering algo

Thanks again