1 Pose of a widget {#tutorial_widget_pose}
4 @prev_tutorial{tutorial_launching_viz}
5 @next_tutorial{tutorial_transformations}
10 In this tutorial you will learn how to
12 - Add widgets to the visualization window
13 - Use Affine3 to set pose of a widget
14 - Rotating and translating a widget along an axis
19 You can download the code from [here ](https://github.com/opencv/opencv/tree/3.4/samples/cpp/tutorial_code/viz/widget_pose.cpp).
20 @include samples/cpp/tutorial_code/viz/widget_pose.cpp
25 Here is the general structure of the program:
27 - Create a visualization window.
30 viz::Viz3d myWindow("Coordinate Frame");
32 - Show coordinate axes in the window using CoordinateSystemWidget.
34 /// Add coordinate axes
35 myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
37 - Display a line representing the axis (1,1,1).
39 /// Add line to represent (1,1,1) axis
40 viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f));
41 axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
42 myWindow.showWidget("Line Widget", axis);
46 /// Construct a cube widget
47 viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue());
48 cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
49 myWindow.showWidget("Cube Widget", cube_widget);
51 - Create rotation matrix from rodrigues vector
53 /// Rotate around (1,1,1)
54 rot_vec.at<float>(0,0) += CV_PI * 0.01f;
55 rot_vec.at<float>(0,1) += CV_PI * 0.01f;
56 rot_vec.at<float>(0,2) += CV_PI * 0.01f;
61 Rodrigues(rot_vec, rot_mat);
63 - Use Affine3f to set pose of the cube.
66 Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
67 myWindow.setWidgetPose("Cube Widget", pose);
69 - Animate the rotation using wasStopped and spinOnce
71 while(!myWindow.wasStopped())
75 myWindow.spinOnce(1, true);
82 Here is the result of the program.
86 <iframe width="420" height="315" src="https://www.youtube.com/embed/22HKMN657U0" frameborder="0" allowfullscreen></iframe>