From 71dc5f8291af1272349e188d8e83f96ae79560fd Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Wed, 7 Aug 2013 16:20:23 +0200 Subject: [PATCH] simulate real cameras by working around vtkUserTransform to set projection matrix --- modules/viz/src/viz3d_impl.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index a24700ce91..cc732f6d7e 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -573,6 +573,16 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera) active_camera.SetViewAngle (camera.getFov()[1] * 180.0f / CV_PI); active_camera.SetClippingRange (camera.getClip()[0], camera.getClip()[1]); window_->SetSize (camera.getWindowSize().width, camera.getWindowSize().height); + + // Use the intrinsic parameters of the camera to simulate more realistically + Matx44f proj_matrix; + camera.computeProjectionMatrix(proj_matrix); + Matx44f old_proj_matrix = convertToMatx(active_camera.GetProjectionTransformMatrix(((float)camera.getWindowSize().width) / camera.getWindowSize().height, -1.0f, 1.0f)); + vtkTransform * transform = vtkTransform::New(); + // This is a hack around not being able to set Projection Matrix + transform->SetMatrix(convertToVtkMatrix(proj_matrix * old_proj_matrix.inv())); + active_camera.SetUserTransform(transform); + transform->Delete(); } /////////////////////////////////////////////////////////////////////////////////////////////