diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index f572059197..d3f5a109cc 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -41,9 +41,6 @@ // * Ozan Tonkal, ozantonkal@gmail.com // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // -// OpenCV Viz module is complete rewrite of -// PCL visualization module (www.pointclouds.org) -// //M*/ #ifndef __OPENCV_VIZ_VIZ3D_HPP__ diff --git a/modules/viz/include/opencv2/viz/widget_accessor.hpp b/modules/viz/include/opencv2/viz/widget_accessor.hpp index 394cfa8587..29352a214b 100644 --- a/modules/viz/include/opencv2/viz/widget_accessor.hpp +++ b/modules/viz/include/opencv2/viz/widget_accessor.hpp @@ -41,9 +41,6 @@ // * Ozan Tonkal, ozantonkal@gmail.com // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // -// OpenCV Viz module is complete rewrite of -// PCL visualization module (www.pointclouds.org) -// //M*/ #ifndef __OPENCV_VIZ_WIDGET_ACCESSOR_HPP__ @@ -69,4 +66,4 @@ namespace cv } } -#endif \ No newline at end of file +#endif diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index cb2dae20e7..0b0c5fc28c 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -41,9 +41,6 @@ // * Ozan Tonkal, ozantonkal@gmail.com // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // -// OpenCV Viz module is complete rewrite of -// PCL visualization module (www.pointclouds.org) -// //M*/ #ifndef __OPENCV_VIZ_WIDGETS_HPP__ @@ -178,28 +175,22 @@ namespace cv WCube(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white()); }; - ///////////////////////////////////////////////////////////////////////////// - /// Compond widgets - - class CV_EXPORTS WCoordinateSystem : public Widget3D - { - public: - WCoordinateSystem(float scale = 1.f); - }; - class CV_EXPORTS WPolyLine : public Widget3D { public: WPolyLine(InputArray points, const Color &color = Color::white()); }; - class CV_EXPORTS WGrid : public Widget3D + ///////////////////////////////////////////////////////////////////////////// + /// Text and image widgets + + class CV_EXPORTS WText : public Widget2D { public: - //! Creates grid at the origin - WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); - //! Creates grid based on the plane equation - WGrid(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); + WText(const String &text, const Point2i &pos, int font_size = 20, const Color &color = Color::white()); + + void setText(const String &text); + String getText() const; }; class CV_EXPORTS WText3D : public Widget3D @@ -211,15 +202,6 @@ namespace cv String getText() const; }; - class CV_EXPORTS WText : public Widget2D - { - public: - WText(const String &text, const Point2i &pos, int font_size = 20, const Color &color = Color::white()); - - void setText(const String &text); - String getText() const; - }; - class CV_EXPORTS WImageOverlay : public Widget2D { public: @@ -239,6 +221,24 @@ namespace cv void setImage(const Mat &image); }; + ///////////////////////////////////////////////////////////////////////////// + /// Compond widgets + + class CV_EXPORTS WCoordinateSystem : public Widget3D + { + public: + WCoordinateSystem(float scale = 1.f); + }; + + class CV_EXPORTS WGrid : public Widget3D + { + public: + //! Creates grid at the origin + WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); + //! Creates grid based on the plane equation + WGrid(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); + }; + class CV_EXPORTS WCameraPosition : public Widget3D { public: @@ -254,6 +254,9 @@ namespace cv explicit WCameraPosition(const Vec2f &fov, const Mat &img, float scale = 1.f, const Color &color = Color::white()); }; + ///////////////////////////////////////////////////////////////////////////// + /// Trajectories + class CV_EXPORTS WTrajectory : public Widget3D { public: @@ -280,7 +283,7 @@ namespace cv }; ///////////////////////////////////////////////////////////////////////////// - /// Cloud widgets + /// Clouds class CV_EXPORTS WCloud: public Widget3D { diff --git a/modules/viz/src/precomp.cpp b/modules/viz/src/precomp.cpp index 834648577c..631a300da2 100644 --- a/modules/viz/src/precomp.cpp +++ b/modules/viz/src/precomp.cpp @@ -41,9 +41,6 @@ // * Ozan Tonkal, ozantonkal@gmail.com // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // -// OpenCV Viz module is complete rewrite of -// PCL visualization module (www.pointclouds.org) -// //M*/ #include "precomp.hpp" diff --git a/modules/viz/src/precomp.hpp b/modules/viz/src/precomp.hpp index 5994aaa1bc..7f09ee0766 100644 --- a/modules/viz/src/precomp.hpp +++ b/modules/viz/src/precomp.hpp @@ -41,9 +41,6 @@ // * Ozan Tonkal, ozantonkal@gmail.com // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // -// OpenCV Viz module is complete rewrite of -// PCL visualization module (www.pointclouds.org) -// //M*/ #ifndef __OPENCV_VIZ_PRECOMP_HPP__ diff --git a/modules/viz/src/viz.cpp b/modules/viz/src/viz.cpp index 6a08dfa34a..445d483de0 100644 --- a/modules/viz/src/viz.cpp +++ b/modules/viz/src/viz.cpp @@ -41,9 +41,6 @@ // * Ozan Tonkal, ozantonkal@gmail.com // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // -// OpenCV Viz module is complete rewrite of -// PCL visualization module (www.pointclouds.org) -// //M*/ #include "precomp.hpp" diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index a7ef9c4374..b38ad29666 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -73,10 +73,10 @@ public: double getDesiredUpdateRate(); /** \brief Returns true when the user tried to close the window */ - bool wasStopped() const { if (interactor_ != NULL) return (stopped_); else return true; } + bool wasStopped() const { return interactor_ ? stopped_ : true; } /** \brief Set the stopped flag back to false */ - void resetStoppedFlag() { if (interactor_ != NULL) stopped_ = false; } + void resetStoppedFlag() { if (interactor_) stopped_ = false; } /** \brief Stop the interaction and close the visualizaton window. */ void close() diff --git a/modules/viz/test/test_precomp.hpp b/modules/viz/test/test_precomp.hpp index 9b98f206b1..ff7606ed9b 100644 --- a/modules/viz/test/test_precomp.hpp +++ b/modules/viz/test/test_precomp.hpp @@ -41,9 +41,6 @@ // * Ozan Tonkal, ozantonkal@gmail.com // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // -// OpenCV Viz module is complete rewrite of -// PCL visualization module (www.pointclouds.org) -// //M*/ #ifdef __GNUC__ diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp index 98811165ab..29cf81ebb2 100644 --- a/modules/viz/test/test_viz3d.cpp +++ b/modules/viz/test/test_viz3d.cpp @@ -41,141 +41,30 @@ //M*/ #include "test_precomp.hpp" - using namespace cv; static cv::Mat cvcloud_load() { cv::Mat cloud(1, 20000, CV_32FC3); - std::ifstream ifs("/Users/nerei/cloud_dragon.ply"); + std::ifstream ifs("d:/cloud_dragon.ply"); std::string str; for(size_t i = 0; i < 11; ++i) std::getline(ifs, str); cv::Point3f* data = cloud.ptr(); - for(size_t i = 0; i < 20000; ++i) + for(size_t i = 0; i < cloud.total(); ++i) ifs >> data[i].x >> data[i].y >> data[i].z; return cloud; } -bool constant_cam = true; -cv::viz::Widget cam_1, cam_coordinates; - -void keyboard_callback(const viz::KeyboardEvent & event, void * cookie) -{ - if (event.keyDown()) - { - if (event.getKeySym() == "space") - { - viz::Viz3d &viz = *((viz::Viz3d *) cookie); - constant_cam = !constant_cam; - if (constant_cam) - { - viz.showWidget("cam_1", cam_1); - viz.showWidget("cam_coordinate", cam_coordinates); - viz.showWidget("cam_text", viz::WText("Global View", Point2i(5,5), 28)); - viz.resetCamera(); - } - else - { - viz.showWidget("cam_text", viz::WText("Cam View", Point2i(5,5), 28)); - viz.removeWidget("cam_1"); - viz.removeWidget("cam_coordinate"); - } - } - } -} - TEST(Viz_viz3d, develop) { + cv::Mat cloud = cvcloud_load(); cv::viz::Viz3d viz("abc"); - - cv::viz::Mesh3d bunny_mesh = cv::viz::Mesh3d::loadMesh("bunny.ply"); - cv::viz::WMesh bunny_widget(bunny_mesh); - bunny_widget.setColor(cv::viz::Color::cyan()); - - cam_1 = cv::viz::WCameraPosition(cv::Vec2f(0.6f, 0.4f), 0.2, cv::viz::Color::green()); - cam_coordinates = cv::viz::WCameraPosition(0.2); - - viz.showWidget("bunny", bunny_widget); - viz.showWidget("cam_1", cam_1, viz::makeCameraPose(Point3f(1.f,0.f,0.f), Point3f(0.f,0.f,0.f), Point3f(0.f,1.f,0.f))); - viz.showWidget("cam_coordinate", cam_coordinates, viz::makeCameraPose(Point3f(1.f,0.f,0.f), Point3f(0.f,0.f,0.f), Point3f(0.f,1.f,0.f))); - - std::vector cam_path; - - for (int i = 0, j = 0; i <= 360; ++i, j+=5) - { - cam_path.push_back(viz::makeCameraPose(Vec3d(0.5*cos(i*CV_PI/180.0), 0.5*sin(j*CV_PI/180.0), 0.5*sin(i*CV_PI/180.0)), Vec3f(0.f, 0.f, 0.f), Vec3f(0.f, 1.f, 0.f))); - } - - int path_counter = 0; - int cam_path_size = cam_path.size(); - - // OTHER WIDGETS - cv::Mat img = imread("opencv.png"); - - int downSample = 4; - - int row_max = img.rows/downSample; - int col_max = img.cols/downSample; - - cv::Mat *clouds = new cv::Mat[img.cols/downSample]; - cv::Mat *colors = new cv::Mat[img.cols/downSample]; - - for (int col = 0; col < col_max; ++col) - { - clouds[col] = Mat::zeros(img.rows/downSample, 1, CV_32FC3); - colors[col] = Mat::zeros(img.rows/downSample, 1, CV_8UC3); - for (int row = 0; row < row_max; ++row) - { - clouds[col].at(row) = Vec3f(downSample * float(col) / img.cols, 1.f-(downSample * float(row) / img.rows), 0.f); - colors[col].at(row) = img.at(row*downSample,col*downSample); - } - } - - for (int col = 0; col < col_max; ++col) - { - std::stringstream strstrm; - strstrm << "cloud_" << col; - viz.showWidget(strstrm.str(), viz::WCloud(clouds[col], colors[col])); - viz.getWidget(strstrm.str()).setRenderingProperty(viz::POINT_SIZE, 3.0); - viz.getWidget(strstrm.str()).setRenderingProperty(viz::OPACITY, 0.45); - } - - viz.showWidget("trajectory", viz::WTrajectory(cam_path, viz::WTrajectory::DISPLAY_PATH, viz::Color::yellow())); - viz.showWidget("cam_text", viz::WText("Global View", Point2i(5,5), 28)); - viz.registerKeyboardCallback(keyboard_callback, (void *) &viz); - - int angle = 0; - - while(!viz.wasStopped()) - { - if (path_counter == cam_path_size) - { - path_counter = 0; - } - - if (!constant_cam) - { - viz.setViewerPose(cam_path[path_counter]); - } - - if (angle == 360) angle = 0; - - cam_1.cast().setPose(cam_path[path_counter]); - cam_coordinates.cast().setPose(cam_path[path_counter++]); - - for (int i = 0; i < col_max; ++i) - { - std::stringstream strstrm; - strstrm << "cloud_" << i; - viz.setWidgetPose(strstrm.str(), Affine3f().translate(Vec3f(-0.5f, 0.f, (float)(-0.7 + 0.2*sin((angle+i*10)*CV_PI / 180.0))))); - } - angle += 10; - viz.spinOnce(42, true); - } - - volatile void* a = (void*)&cvcloud_load; (void)a; //fixing warnings + cv::viz::WCloud c(cloud, cv::Mat(cloud.size(), CV_8UC3, cv::Scalar(0, 255, 0))); + //cv::viz::WCloud c(cloud, cv::viz::Color::bluberry()); + viz.showWidget("c", c); + viz.spin(); }