Log in or register to post comments

Projection Matrix creation?

October 16, 2014 - 3:13pm #1

Hi!  I am looking into how the Projection matrix is created in Vuforia using the Native iOS SDK and I am finding some inconsistencies.  First off, I have reviewed the pages that cover how the projection matrix is created: https://developer.vuforia.com/resources/dev-guide/projection-matrix-explained and https://developer.vuforia.com/resources/dev-guide/camera-parameters.

So, I took the code that creates the projection matrix and tried to create my own.  The results are DIFFERENT than the Vuforia getProjectionGL method.  Here is the code and results:

Create Projection Matrix Manually:

float nearPlane = 2.0f;
float farPlane = 2000.0f;
const QCAR::CameraCalibration& cameraCalibration = QCAR::CameraDevice::getInstance().getCameraCalibration();
QCAR::Vec2F size = cameraCalibration.getSize();
QCAR::Vec2F focalLength = cameraCalibration.getFocalLength();
QCAR::Vec2F principalPoint = cameraCalibration.getPrincipalPoint();
float dx = principalPoint.data[0] - size.data[0] / 2;
float dy = principalPoint.data[1] - size.data[1] / 2;
float x =  2.0f * focalLength.data[0] / size.data[0];
float y = -2.0f * focalLength.data[1] / size.data[1];
float a =  2.0f * dx / size.data[0];
float b = -2.0f * (dy + 1.0f) / size.data[1];
float c = (farPlane + nearPlane) / (farPlane - nearPlane);
float d = -nearPlane * (1.0f + c);
QCAR::Matrix44F mat;
mat.data[0] = x;      mat.data[1] = 0.0f;   mat.data[2] = 0.0f;  mat.data[3] = 0.0f;
mat.data[4] = 0.0f;   mat.data[5] = y;      mat.data[6] = 0.0f;  mat.data[7] = 0.0f;
mat.data[8] = a;      mat.data[9] = b;      mat.data[10] = c;    mat.data[11] = 1.0f;
mat.data[12] = 0.0f;  mat.data[13] = 0.0f;  mat.data[14] = d;    mat.data[15] = 0.0f;

Get Projection Matrix via Vuforia:

float nearPlane = 2.0f;
float farPlane = 2000.0f;
QCAR::Matrix44F projectionMatrix = QCAR::Tool::getProjectionGL(cameraCalibration, nearPlane, farPlane);

Results:

mat.data:
  1.86,  0.00,  0.00,  0.00
  0.00, -2.48,  0.00,  0.00
  0.00,  0.00,  1.00,  1.00
  0.00,  0.00, -4.00,  0.00
projectionMatrix.data:
  0.00, -1.86,  0.00,  0.00
 -2.48,  0.00,  0.00,  0.00
  0.01, -0.00,  1.00,  1.00
  0.00,  0.00, -4.00,  0.00

As one can see, the two matrices are DIFFERENT.  Why?  The code I used above was copied exactly from https://developer.vuforia.com/resources/dev-guide/camera-parameters and the code can also be found at https://developer.vuforia.com/forum/faq/technical-how-do-i-build-my-own-camera-projection-matrix.

 

Projection Matrix creation?

October 30, 2017 - 7:05pm #4

QCAR::    <<Is C++?

Unity C # how to write?

Projection Matrix creation?

August 12, 2015 - 4:03am #3

I am also having the same problem... the correct projection matrix according to the code given in the previous post should be :

P_correct =

 

                   1.7119     0       0        0

                     0      2.2843    0       0

                  -0.4971 0.5168 1.0040 1.0000

                    0        0  -20.0401   0

 

But Vuforia is computing vuforiaAppSession.getProjectionMatrix().getData() as:

 

P =

 

0       -1.7119    0       0

-2.2843    0       0      0

0.0420 -0.0089 1.0040  1.0000

0         0   -20.0401   0

 

Why is this discrepancy?? This is causing gluproject to return wrong window coordinates for object coordinates other than [0,0,0].

 

Somebody please help!!

 

 

Projection Matrix creation?

October 28, 2014 - 6:48am #2

Have you tried both Landscape and Portrait modes ?

I think the article refers to one case only, whereas the QCAR::Tool::getProjectionGL function actually takes into account the screen orientation,

Log in or register to post comments