Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/viz/test/test_tutorial3.cpp
16354 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
#include "test_precomp.hpp"
5
6
namespace opencv_test { namespace {
7
8
/**
9
* @function main
10
*/
11
static void tutorial3(bool camera_pov)
12
{
13
/// Create a window
14
viz::Viz3d myWindow("Coordinate Frame");
15
16
/// Add coordinate axes
17
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
18
19
/// Let's assume camera has the following properties
20
Point3d 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);
21
22
/// We can get the pose of the cam using makeCameraPose
23
Affine3d camera_pose = viz::makeCameraPose(cam_origin, cam_focal_point, cam_y_dir);
24
25
/// We can get the transformation matrix from camera coordinate system to global using
26
/// - makeTransformToGlobal. We need the axes of the camera
27
Affine3d 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);
28
29
/// Create a cloud widget.
30
Mat dragon_cloud = viz::readCloud(get_dragon_ply_file_path());
31
viz::WCloud cloud_widget(dragon_cloud, viz::Color::green());
32
33
/// Pose of the widget in camera frame
34
Affine3d 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));
35
/// Pose of the widget in global frame
36
Affine3d cloud_pose_global = transform * cloud_pose;
37
38
/// Visualize camera frame
39
myWindow.showWidget("CPW_FRUSTUM", viz::WCameraPosition(Vec2f(0.889484f, 0.523599f)), camera_pose);
40
if (!camera_pov)
41
myWindow.showWidget("CPW", viz::WCameraPosition(0.5), camera_pose);
42
43
/// Visualize widget
44
myWindow.showWidget("bunny", cloud_widget, cloud_pose_global);
45
46
/// Set the viewer pose to that of camera
47
if (camera_pov)
48
myWindow.setViewerPose(camera_pose);
49
50
/// Start event loop.
51
myWindow.spin();
52
}
53
54
TEST(Viz, tutorial3_global_view)
55
{
56
tutorial3(false);
57
}
58
59
TEST(Viz, tutorial3_camera_view)
60
{
61
tutorial3(true);
62
}
63
64
}} // namespace
65
66