From: Anatoly Baksheev Date: Sun, 17 Nov 2013 11:18:15 +0000 (+0400) Subject: added viz tutorial 3 test X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~3694^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=efcc341219872ae830a8c044f9e5dbd6c1afddb6;p=platform%2Fupstream%2Fopencv.git added viz tutorial 3 test --- diff --git a/modules/viz/test/test_precomp.hpp b/modules/viz/test/test_precomp.hpp index 9ca98d7..9b98f20 100644 --- a/modules/viz/test/test_precomp.hpp +++ b/modules/viz/test/test_precomp.hpp @@ -60,6 +60,8 @@ #include "opencv2/ts.hpp" #include #include +#include +#include #include #include diff --git a/modules/viz/test/test_tutorial3.cpp b/modules/viz/test/test_tutorial3.cpp new file mode 100644 index 0000000..27544a9 --- /dev/null +++ b/modules/viz/test/test_tutorial3.cpp @@ -0,0 +1,86 @@ +#include "test_precomp.hpp" + +using namespace cv; +using namespace std; + +/** + * @function cvcloud_load + * @brief load bunny.ply + */ +Mat cvcloud_load() +{ + Mat cloud(1, 20000, CV_32FC3); + ifstream ifs("d:/cloud_dragon.ply"); + + string str; + for(size_t i = 0; i < 12; ++i) + getline(ifs, str); + + Point3f* data = cloud.ptr(); + //float dummy1, dummy2; + for(size_t i = 0; i < 20000; ++i) + ifs >> data[i].x >> data[i].y >> data[i].z;// >> dummy1 >> dummy2; + + //cloud *= 5.0f; + return cloud; +} + +/** + * @function main + */ +void tutorial3(bool camera_pov) +{ + /// Create a window + viz::Viz3d myWindow("Coordinate Frame"); + + /// Add coordinate axes + myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); + + /// Let's assume camera has the following properties + Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f); + + /// We can get the pose of the cam using makeCameraPose + Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir); + + /// We can get the transformation matrix from camera coordinate system to global using + /// - makeTransformToGlobal. We need the axes of the camera + Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos); + + /// Create a cloud widget. + Mat bunny_cloud = cvcloud_load(); + viz::WCloud cloud_widget(bunny_cloud, viz::Color::green()); + + /// Pose of the widget in camera frame + Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f)); + /// Pose of the widget in global frame + Affine3f cloud_pose_global = transform * cloud_pose; + + /// Visualize camera frame + if (!camera_pov) + { + viz::WCameraPosition cpw(0.5); // Coordinate axes + viz::WCameraPosition cpw_frustum(Vec2f(0.889484, 0.523599)); // Camera frustum + myWindow.showWidget("CPW", cpw, cam_pose); + myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); + } + + /// Visualize widget + myWindow.showWidget("bunny", cloud_widget, cloud_pose_global); + + /// Set the viewer pose to that of camera + if (camera_pov) + myWindow.setViewerPose(cam_pose); + + /// Start event loop. + myWindow.spin(); +} + +TEST(Viz_viz3d, tutorial3_global_view) +{ + tutorial3(false); +} + +TEST(Viz_viz3d, tutorial3_camera_view) +{ + tutorial3(true); +} diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp index eac0bd0..2acb5a3 100644 --- a/modules/viz/test/test_viz3d.cpp +++ b/modules/viz/test/test_viz3d.cpp @@ -40,13 +40,11 @@ // //M*/ #include "test_precomp.hpp" -#include -#include -#include + using namespace cv; -cv::Mat cvcloud_load() +static cv::Mat cvcloud_load() { cv::Mat cloud(1, 20000, CV_32FC3); std::ifstream ifs("/Users/nerei/cloud_dragon.ply"); @@ -90,7 +88,7 @@ void keyboard_callback(const viz::KeyboardEvent & event, void * cookie) } } -TEST(Viz_viz3d, accuracy) +TEST(Viz_viz3d, develop) { cv::viz::Viz3d viz("abc"); @@ -178,4 +176,6 @@ TEST(Viz_viz3d, accuracy) angle += 10; viz.spinOnce(42, true); } + + volatile void* a = (void*)&cvcloud_load; (void)a; //fixing warnings }