Path: blob/master/modules/viz/test/test_tutorial3.cpp
16354 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3#include "test_precomp.hpp"45namespace opencv_test { namespace {67/**8* @function main9*/10static void tutorial3(bool camera_pov)11{12/// Create a window13viz::Viz3d myWindow("Coordinate Frame");1415/// Add coordinate axes16myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());1718/// Let's assume camera has the following properties19Point3d cam_origin(3.0, 3.0, 3.0), cam_focal_point(3.0, 3.0, 2.0), cam_y_dir(-1.0, 0.0, 0.0);2021/// We can get the pose of the cam using makeCameraPose22Affine3d camera_pose = viz::makeCameraPose(cam_origin, cam_focal_point, cam_y_dir);2324/// We can get the transformation matrix from camera coordinate system to global using25/// - makeTransformToGlobal. We need the axes of the camera26Affine3d transform = viz::makeTransformToGlobal(Vec3d(0.0, -1.0, 0.0), Vec3d(-1.0, 0.0, 0.0), Vec3d(0.0, 0.0, -1.0), cam_origin);2728/// Create a cloud widget.29Mat dragon_cloud = viz::readCloud(get_dragon_ply_file_path());30viz::WCloud cloud_widget(dragon_cloud, viz::Color::green());3132/// Pose of the widget in camera frame33Affine3d cloud_pose = Affine3d().rotate(Vec3d(0.0, CV_PI/2, 0.0)).rotate(Vec3d(0.0, 0.0, CV_PI)).translate(Vec3d(0.0, 0.0, 3.0));34/// Pose of the widget in global frame35Affine3d cloud_pose_global = transform * cloud_pose;3637/// Visualize camera frame38myWindow.showWidget("CPW_FRUSTUM", viz::WCameraPosition(Vec2f(0.889484f, 0.523599f)), camera_pose);39if (!camera_pov)40myWindow.showWidget("CPW", viz::WCameraPosition(0.5), camera_pose);4142/// Visualize widget43myWindow.showWidget("bunny", cloud_widget, cloud_pose_global);4445/// Set the viewer pose to that of camera46if (camera_pov)47myWindow.setViewerPose(camera_pose);4849/// Start event loop.50myWindow.spin();51}5253TEST(Viz, tutorial3_global_view)54{55tutorial3(false);56}5758TEST(Viz, tutorial3_camera_view)59{60tutorial3(true);61}6263}} // namespace646566