Log in or register to post comments

Projection Matrix example doesn't match example

February 4, 2015 - 1:12am #1

The Vufora projection matrix page

 

https://developer.vuforia.com/resources/dev-guide/camera-parameters

 

The projection matrix is created using device-specific camera parameters.  Here is the code for building the projection matrix from the camera parameters

The issue is, it doesn't. The resulting matrix does not match the projectionMatrix generated by the call getProjectionGL. Can someone please address this discrepancy?

 

    float nearPlane = 0.01f;
    float farPlane = 1000.0f;
  
    const QCAR::CameraCalibration& cameraCalibration = QCAR::CameraDevice::getInstance().getCameraCalibration();
    QCAR::Matrix44F projectionMatrix = QCAR::Tool::getProjectionGL(cameraCalibration, nearPlane, farPlane);
    // The following code reproduces the projectionMatrix above using the camera parameters
    QCAR::Vec2F size = cameraCalibration.getSize();
    QCAR::Vec2F focalLength = cameraCalibration.getFocalLength();
    QCAR::Vec2F principalPoint = cameraCalibration.getPrincipalPoint();
    float sizeX = size.data[0];
    float sizeY = size.data[1];

    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;

 

Projection Matrix example doesn't match example

February 5, 2015 - 1:23pm #2
Log in or register to post comments