From 0bb89e767a8f40f6a14683fd0288d8739a18d297 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sun, 4 Aug 2013 17:01:41 +0200 Subject: [PATCH] fix field of view formula in camera class, implement get camera --- modules/viz/src/types.cpp | 2 +- modules/viz/src/viz3d_impl.cpp | 10 ++++++++++ modules/viz/src/viz3d_impl.hpp | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp index e95f67e567..827b8b3bc9 100644 --- a/modules/viz/src/types.cpp +++ b/modules/viz/src/types.cpp @@ -192,7 +192,7 @@ void cv::viz::Camera2::setWindowSize(const Size &window_size) float aspect_ratio_new = window_size.width / window_size.height; if (principal_point_[0] < 0.0f) - fov_[0] = 2 * atan2(tan(fov_[0] * 0.5), aspect_ratio_new); // This assumes that the lens is symmetric! + fov_[0] = 2 * atan2(tan(fov_[1] * 0.5), aspect_ratio_new); // This assumes that the lens is symmetric! else fov_[0] = (atan2(principal_point_[0],focal_[0]) + atan2(window_size.width-principal_point_[0],focal_[0])) * 180 / CV_PI; } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 78c1441a36..f764c77558 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -603,6 +603,16 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera2 &camera) window_->SetSize (static_cast (camera.getWindowSize().width), static_cast (camera.getWindowSize().height)); } +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::getCamera(viz::Camera2 &camera) +{ + vtkCamera& active_camera = *renderer_->GetActiveCamera(); + camera.setFov(Vec2f(0.0, active_camera.GetViewAngle() * CV_PI / 180.0f)); + camera.setClip(Vec2d(active_camera.GetClippingRange())); + camera.setWindowSize(Size(renderer_->GetRenderWindow()->GetSize()[0], + renderer_->GetRenderWindow()->GetSize()[1])); +} + ///////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose) { diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 26bafd3428..5bd4ebdea6 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -111,6 +111,7 @@ public: // and 'Camera' class itself with various constructors/fields void setCamera(const Camera2 &camera); + void getCamera(Camera2 &camera); void initCameraParameters (); /** \brief Initialize camera parameters with some default values. */ bool cameraParamsSet () const; /** \brief Checks whether the camera parameters were manually loaded from file.*/