From f445f76213be9337077cf78bc790ba39b2c452fc Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 3 Aug 2013 16:33:11 +0200 Subject: [PATCH] initial setCamera implementation --- modules/viz/include/opencv2/viz/viz3d.hpp | 1 + modules/viz/src/types.cpp | 2 +- modules/viz/src/viz3d.cpp | 1 + modules/viz/src/viz3d_impl.cpp | 12 ++++++++++++ modules/viz/src/viz3d_impl.hpp | 2 ++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index 8fbaacd55a..e173fcfca0 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -39,6 +39,7 @@ namespace cv void updateWidgetPose(const String &id, const Affine3f &pose); Affine3f getWidgetPose(const String &id) const; + void setCamera(const Camera2 &camera); Affine3f getViewerPose(); void setViewerPose(const Affine3f &pose); diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp index 4ea1b32d37..e95f67e567 100644 --- a/modules/viz/src/types.cpp +++ b/modules/viz/src/types.cpp @@ -167,7 +167,7 @@ cv::viz::Camera2::Camera2(const Vec2f &fov, const Size &window_size) setClip(Vec2d(0.01, 1000.01)); // Default clipping window_size_ = window_size; fov_ = fov; - principal_point_ = Vec2f(-1.0f, -1.0f); // Symmetric lens + principal_point_ = Vec2f(-1.0f, -1.0f); // Default symmetric lens focal_ = Vec2f(-1.0f, -1.0f); } diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 6bf00172c1..8aa97419f7 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -46,5 +46,6 @@ void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3f &pose) { imp void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3f &pose) { impl_->updateWidgetPose(id, pose); } cv::Affine3f cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); } +void cv::viz::Viz3d::setCamera(const Camera2 &camera) { impl_->setCamera(camera); } void cv::viz::Viz3d::setViewerPose(const Affine3f &pose) { impl_->setViewerPose(pose); } cv::Affine3f cv::viz::Viz3d::getViewerPose() { return impl_->getViewerPose(); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index fb72047c5c..78c1441a36 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -591,6 +591,18 @@ void cv::viz::Viz3d::VizImpl::getCameras (cv::viz::Camera& camera) camera.window_pos = cv::Vec2d::all(0); } +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::setCamera(const Camera2 &camera) +{ + vtkCamera& active_camera = *renderer_->GetActiveCamera(); + + // Set the intrinsic parameters of the camera + active_camera.SetUseHorizontalViewAngle (0); // Horizontal view angle is set based on the window size + active_camera.SetViewAngle (camera.getFov()[1] * 180.0f / CV_PI); + active_camera.SetClippingRange (camera.getClip()[0], camera.getClip()[1]); + window_->SetSize (static_cast (camera.getWindowSize().width), static_cast (camera.getWindowSize().height)); +} + ///////////////////////////////////////////////////////////////////////////////////////////// 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 704cf08a87..26bafd3428 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -109,6 +109,8 @@ public: // //////////////////////////////////////////////////////////////////////////////////// // All camera methods to refactor into set/getViewwerPose, setCamera() // and 'Camera' class itself with various constructors/fields + + void setCamera(const 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.*/