Re: [osg-users] Camera intrinsics

2011-04-06 Thread benedikt naessens

Keith Parkins wrote:
 After looking at this again, I am unclear as to whether you have built
 the projection matrix from the intrinsic parameters. I was assuming that
 you had made it by hand. To do that you would do something like this:
 
 //-//
  
 // The _intrinsic variable holds the five values for the intrinsic
 // matrix. The intrinsic * our pixel transform to get the projections
 // matrix. The intrinsic values (itr[]) are given as five doubles
 // such that: 
 //
 //| itr[0] itr[1] itr[2]  |
 //|   0itr[3] itr[4]  |
 //|   0  0  0 |
 //
 //| alpha_u gamma u_0  |
 //|   0alpha_v v_0 |
 //|   0  0  0  |
 //
 //-//
 
 void 
 -Camera::calcProjection() {
 double alpha_u, alpha_v;
 
 // calc alphas
 alpha_u = _intrinsic[0];
 double cot_theta = - _intrinsic[1]/_intrinsic[0];
 double sin_theta = sqrt(1/(1+cot_theta*cot_theta));
 alpha_v = _intrinsic[3] * sin_theta;
 
 double skew = _intrinsic[1];
 
 double u0, v0;
 u0 = _intrinsic[2]; v0 = _intrinsic[4];
 
 double left = -u0 / alpha_u * _near;
 double bottom = (_screen_height-v0) / alpha_v * _near;
 double right = (_screen_width - u0) / alpha_u * _near;
 double top = -v0 / alpha_v * _near;
 
 _projection[0] = 2 * _near / (right - left);
 _projection[4] = 2 * _near * skew / ((right - left) * alpha_u);
 _projection[5] = 2 * _near / (top - bottom);
 _projection[8] = -(right + left)/(right - left);
 _projection[9] = -(top + bottom)/(top - bottom);
 _projection[10] = (_far + _near) / (_far - _near);
 _projection[11] = 1;
 _projection[14] = -2 * _far * _near/(_far-_near);
 
 |}
 
 
 /lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
 
 

___
osg-users mailing list

http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

 --
Post generated by Mail2Forum[/quote]

There seems to be a mismatch between the projection matrix generated by e.g. 
makePerspective and the projection matrix elements you suggest here.

When I do the comparison between the two, it seems that: 
_projection[5], _projection[8], _projection[9] and _projection[11] have 
opposite signs. 

I'm also a bit surprised that the projection matrix generated by OSG 
(makePerspective) has -1 instead of 1 for _projection[11]. Maybe that has 
something to do with the inversion of the Y axis (0,0 in the bottom left 
instead of the top left) ?

Can you give me a suggestion why these differences exist ?

Thanks !
Benedikt.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=38253#38253





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Camera intrinsics

2011-04-06 Thread Keith Parkins

Hi Benedikt,

I don't have time to look at this right now, but off the top of my head
the sign difference that you noticed may be because I grabbed this from
a reverse projection that I did (the projection was bounced off some
mirrors to a back projection which in turn was viewed by looking into
another mirror). So if everything was flipped when you tried this, that
was probably the reason why.

-K

On Wed, 6 Apr 2011, benedikt naessens wrote:



Keith Parkins wrote:

After looking at this again, I am unclear as to whether you have built
the projection matrix from the intrinsic parameters. I was assuming that
you had made it by hand. To do that you would do something like this:

//-//
// The _intrinsic variable holds the five values for the intrinsic
// matrix. The intrinsic * our pixel transform to get the projections
// matrix. The intrinsic values (itr[]) are given as five doubles
// such that:
//
//| itr[0] itr[1] itr[2]  |
//|   0itr[3] itr[4]  |
//|   0  0  0 |
//
//| alpha_u gamma u_0  |
//|   0alpha_v v_0 |
//|   0  0  0  |
//
//-//

void
-Camera::calcProjection() {
double alpha_u, alpha_v;

// calc alphas
alpha_u = _intrinsic[0];
double cot_theta = - _intrinsic[1]/_intrinsic[0];
double sin_theta = sqrt(1/(1+cot_theta*cot_theta));
alpha_v = _intrinsic[3] * sin_theta;

double skew = _intrinsic[1];

double u0, v0;
u0 = _intrinsic[2]; v0 = _intrinsic[4];

double left = -u0 / alpha_u * _near;
double bottom = (_screen_height-v0) / alpha_v * _near;
double right = (_screen_width - u0) / alpha_u * _near;
double top = -v0 / alpha_v * _near;

_projection[0] = 2 * _near / (right - left);
_projection[4] = 2 * _near * skew / ((right - left) * alpha_u);
_projection[5] = 2 * _near / (top - bottom);
_projection[8] = -(right + left)/(right - left);
_projection[9] = -(top + bottom)/(top - bottom);
_projection[10] = (_far + _near) / (_far - _near);
_projection[11] = 1;
_projection[14] = -2 * _far * _near/(_far-_near);

|}


/lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




___
osg-users mailing list

http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

--
Post generated by Mail2Forum[/quote]

There seems to be a mismatch between the projection matrix generated by e.g. 
makePerspective and the projection matrix elements you suggest here.

When I do the comparison between the two, it seems that:
_projection[5], _projection[8], _projection[9] and _projection[11] have 
opposite signs.

I'm also a bit surprised that the projection matrix generated by OSG 
(makePerspective) has -1 instead of 1 for _projection[11]. Maybe that has 
something to do with the inversion of the Y axis (0,0 in the bottom left 
instead of the top left) ?

Can you give me a suggestion why these differences exist ?

Thanks !
Benedikt.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=38253#38253





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



Keith ParkinsU of R Center for Visual Science
kpark...@cvs.rochester.edu   Meliora Hall, Room 253
office: (585) 275-2460   lab: (585) 275-2230
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Camera intrinsics

2010-07-28 Thread Mourad Boufarguine
Hi Ricky,

This link may help you :
http://old.uvr.gist.ac.kr/wlee/web/techReports/ar/Camera%20Models.html

http://old.uvr.gist.ac.kr/wlee/web/techReports/ar/Camera%20Models.html
Mourad
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Camera intrinsics

2010-07-27 Thread Ricky Flintoff
Hi,

I have a quick question. I looked up online on setting camera intrinsics (5 
parameters, including radial distortion). Would I be using 
viewer.getCamera()-setProjectionMatrixAsPerspective(intrinsic_parameter_matrix)?
 Also, can I do this (with a different matrix) before rendering each frame? 

Thank you!

Cheers,
Ricky

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30318#30318





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Camera intrinsics

2010-07-27 Thread Keith Parkins

Use camera-setProjectionMatrix(intrinsic_parameter_matrix);

Not sure what you are trying to do with respect to the other question
you have.

On Tue, 27 Jul 2010, Ricky Flintoff wrote:


Hi,

I have a quick question. I looked up online on setting camera intrinsics (5 
parameters, including radial distortion). Would I be using 
viewer.getCamera()-setProjectionMatrixAsPerspective(intrinsic_parameter_matrix)?
 Also, can I do this (with a different matrix) before rendering each frame?

Thank you!

Cheers,
Ricky

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30318#30318





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



Keith ParkinsU of R Center for Visual Science
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Camera intrinsics

2010-07-27 Thread Ricky Flintoff
Thank you! I am essentially changing the view (using setViewMatrix) before 
rendering each frame. With each new view matrix, I have a different set of 
intrinsic parameters and I was wondering if I can set those again. In essence, 
can I repeatedly change intrinsic parameters of the camera?


Keith Parkins wrote:
 Use camera-setProjectionMatrix(intrinsic_parameter_matrix);
 
 Not sure what you are trying to do with respect to the other question
 you have.
 
 On Tue, 27 Jul 2010, Ricky Flintoff wrote:
 
 
  Hi,
  
  I have a quick question. I looked up online on setting camera intrinsics (5 
  parameters, including radial distortion). Would I be using 
  viewer.getCamera()-setProjectionMatrixAsPerspective(intrinsic_parameter_matrix)?
   Also, can I do this (with a different matrix) before rendering each frame?
  
  Thank you!
  
  Cheers,
  Ricky
  
  --
  Read this topic online here:
  http://forum.openscenegraph.org/viewtopic.php?p=30318#30318
  
  
  
  
  
  ___
  osg-users mailing list
  
  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
  
  
 
 Keith ParkinsU of R Center for Visual Science
 ___
 osg-users mailing list
 
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
 
  --
 Post generated by Mail2Forum


--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30320#30320





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Camera intrinsics

2010-07-27 Thread Keith Parkins

After looking at this again, I am unclear as to whether you have built
the projection matrix from the intrinsic parameters. I was assuming that
you had made it by hand. To do that you would do something like this:

//-// 
// The _intrinsic variable holds the five values for the intrinsic

// matrix. The intrinsic * our pixel transform to get the projections
// matrix. The intrinsic values (itr[]) are given as five doubles
// such that: 
//

//| itr[0] itr[1] itr[2]  |
//|   0itr[3] itr[4]  |
//|   0  0  0 |
//
//| alpha_u gamma u_0  |
//|   0alpha_v v_0 |
//|   0  0  0  |
//
//-//

void 
-Camera::calcProjection() {

   double alpha_u, alpha_v;

   // calc alphas
   alpha_u = _intrinsic[0];
   double cot_theta = - _intrinsic[1]/_intrinsic[0];
   double sin_theta = sqrt(1/(1+cot_theta*cot_theta));
   alpha_v = _intrinsic[3] * sin_theta;

   double skew = _intrinsic[1];

   double u0, v0;
   u0 = _intrinsic[2]; v0 = _intrinsic[4];

   double left = -u0 / alpha_u * _near;
   double bottom = (_screen_height-v0) / alpha_v * _near;
   double right = (_screen_width - u0) / alpha_u * _near;
   double top = -v0 / alpha_v * _near;

   _projection[0] = 2 * _near / (right - left);
   _projection[4] = 2 * _near * skew / ((right - left) * alpha_u);
   _projection[5] = 2 * _near / (top - bottom);
   _projection[8] = -(right + left)/(right - left);
   _projection[9] = -(top + bottom)/(top - bottom);
   _projection[10] = (_far + _near) / (_far - _near);
   _projection[11] = 1;
   _projection[14] = -2 * _far * _near/(_far-_near);

|}


On Tue, 27 Jul 2010, Ricky Flintoff wrote:


Hi,

I have a quick question. I looked up online on setting camera intrinsics (5 
parameters, including radial distortion). Would I be using 
viewer.getCamera()-setProjectionMatrixAsPerspective(intrinsic_parameter_matrix)?
 Also, can I do this (with a different matrix) before rendering each frame?

Thank you!

Cheers,
Ricky

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30318#30318





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Camera intrinsics

2010-07-27 Thread Ricky Flintoff
Hi,

Oh wow! Thank you very very much!

Thank you!

Cheers,
Ricky

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30328#30328





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Camera intrinsics

2010-07-27 Thread Ricky Flintoff
Hi,

Sorry! I have a couple of more questions. Whats _near and _far? Also, is there 
any reference for these equations?

Thank you again for your tremendous help. 

Cheers,
Ricky

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30330#30330





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org