1 Pose of a widget {#tutorial_widget_pose} 2 ================ 3 4 Goal 5 ---- 6 7 In this tutorial you will learn how to 8 9 - Add widgets to the visualization window 10 - Use Affine3 to set pose of a widget 11 - Rotating and translating a widget along an axis 12 13 Code 14 ---- 15 16 You can download the code from [here ](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/viz/widget_pose.cpp). 17 @include samples/cpp/tutorial_code/viz/widget_pose.cpp 18 19 Explanation 20 ----------- 21 22 Here is the general structure of the program: 23 24 - Create a visualization window. 25 @code{.cpp} 26 /// Create a window 27 viz::Viz3d myWindow("Coordinate Frame"); 28 @endcode 29 - Show coordinate axes in the window using CoordinateSystemWidget. 30 @code{.cpp} 31 /// Add coordinate axes 32 myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); 33 @endcode 34 - Display a line representing the axis (1,1,1). 35 @code{.cpp} 36 /// Add line to represent (1,1,1) axis 37 viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f)); 38 axis.setRenderingProperty(viz::LINE_WIDTH, 4.0); 39 myWindow.showWidget("Line Widget", axis); 40 @endcode 41 - Construct a cube. 42 @code{.cpp} 43 /// Construct a cube widget 44 viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue()); 45 cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); 46 myWindow.showWidget("Cube Widget", cube_widget); 47 @endcode 48 - Create rotation matrix from rodrigues vector 49 @code{.cpp} 50 /// Rotate around (1,1,1) 51 rot_vec.at<float>(0,0) += CV_PI * 0.01f; 52 rot_vec.at<float>(0,1) += CV_PI * 0.01f; 53 rot_vec.at<float>(0,2) += CV_PI * 0.01f; 54 55 ... 56 57 Mat rot_mat; 58 Rodrigues(rot_vec, rot_mat); 59 @endcode 60 - Use Affine3f to set pose of the cube. 61 @code{.cpp} 62 /// Construct pose 63 Affine3f pose(rot_mat, Vec3f(translation, translation, translation)); 64 myWindow.setWidgetPose("Cube Widget", pose); 65 @endcode 66 - Animate the rotation using wasStopped and spinOnce 67 @code{.cpp} 68 while(!myWindow.wasStopped()) 69 { 70 ... 71 72 myWindow.spinOnce(1, true); 73 } 74 @endcode 75 76 Results 77 ------- 78 79 Here is the result of the program. 80 81 \htmlonly 82 <div align="center"> 83 <iframe width="420" height="315" src="https://www.youtube.com/embed/22HKMN657U0" frameborder="0" allowfullscreen></iframe> 84 </div> 85 \endhtmlonly 86