Commit da30d7c2 authored by Matt Clarkson's avatar Matt Clarkson

Fixed camera calibration transposed matrix & compute in double precision.

parent 7c9ad82a
......@@ -45,8 +45,8 @@ void CalibratedCamera::setIntrinsicParameters(float fx, float fy, float cx, floa
//----------------------------------------------------------------------------
void CalibratedCamera::updateCalibration()
{
float znear = mNearPlane;
float zfar = mFarPlane;
double znear = mNearPlane;
double zfar = mFarPlane;
// Inspired by: http://strawlab.org/2011/11/05/augmented-reality-with-OpenGL/
/*
......@@ -56,10 +56,10 @@ void CalibratedCamera::updateCalibration()
[ 0, 0, -1, 0]
*/
mat4 proj;
dmat4 proj;
proj.setNull();
proj.e(0, 0) = 2 * mFx / mImageWidth;
proj.e(0, 1) = -2 * 0.0f / mImageWidth;
proj.e(0, 1) = -2 * 0 / mImageWidth;
proj.e(0, 2) = ( mImageWidth - 2 * mCx ) / mImageWidth;
proj.e(1, 1) = 2 * ( mFy / mPixelAspectRatio ) / ( mImageHeight / mPixelAspectRatio );
proj.e(1, 2) = ( - ( mImageHeight / mPixelAspectRatio ) + 2 * ( mCy / mPixelAspectRatio ) ) / ( mImageHeight / mPixelAspectRatio );
......@@ -67,21 +67,19 @@ void CalibratedCamera::updateCalibration()
proj.e(2, 3) = - 2 * zfar * znear / ( zfar - znear );
proj.e(3, 2) = -1;
proj.transpose();
setProjectionMatrix((mat4)proj, vl::PMT_UserProjection);
setProjectionMatrix(proj, vl::PMT_UserProjection);
float widthScale = (float) mScreenWidth / (float) mImageWidth;
float heightScale = (float) mScreenHeight / ( (float) mImageHeight / mPixelAspectRatio );
double widthScale = (double) mScreenWidth / (double) mImageWidth;
double heightScale = (double) mScreenHeight / ( (double) mImageHeight / mPixelAspectRatio );
int vpw = mScreenWidth;
int vph = mScreenHeight;
if ( widthScale < heightScale ) {
vph = (int) ( ( (float) mImageHeight / mPixelAspectRatio ) * widthScale );
vph = (int) ( ( (double) mImageHeight / mPixelAspectRatio ) * widthScale );
}
else {
vpw = (int) ( (float) mImageWidth * heightScale );
vpw = (int) ( (double) mImageWidth * heightScale );
}
int vpx = mScreenWidth / 2 - vpw / 2;
......@@ -89,6 +87,21 @@ void CalibratedCamera::updateCalibration()
viewport()->set( vpx, vpy, vpw, vph );
// debug
#if 0
printf("\nVL Calibration params:\n");
printf("Cxy: %.2f, %.2f\n", mCx, mCy);
printf("Fxy: %.2f, %.2f\n", mFx, mFy);
printf("Ixy: %d, %d, aspect: %.2f\n", mImageWidth, mImageHeight, mPixelAspectRatio);
printf("Z near & far: %.2f, %.2f\n", znear, zfar);
printf("VP: %d, %d, %d, %d\n", vpx, vpy, vpw, vph);
printf("\nProjection matrix:\n");
double* m = proj.ptr();
for(int i=0; i<4; ++i, m += 4) {
printf("%.2f, %.2f, %.2f, %.2f\n", m[0], m[1], m[2], m[3]);
}
#endif
// Scissor test can be enabled externally by the caller
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment