• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file widget_pose.cpp
3  * @brief Setting pose of a widget
4  * @author Ozan Cagri Tonkal
5  */
6 
7 #include <opencv2/viz.hpp>
8 #include <opencv2/calib3d.hpp>
9 #include <iostream>
10 
11 using namespace cv;
12 using namespace std;
13 
14 /**
15  * @function help
16  * @brief Display instructions to use this tutorial program
17  */
help()18 void help()
19 {
20     cout
21     << "--------------------------------------------------------------------------"   << endl
22     << "This program shows how to visualize a cube rotated around (1,1,1) and shifted "
23     << "using Rodrigues vector."                                                      << endl
24     << "Usage:"                                                                       << endl
25     << "./widget_pose"                                                                << endl
26     << endl;
27 }
28 
29 /**
30  * @function main
31  */
main()32 int main()
33 {
34     help();
35 
36     /// Create a window
37     viz::Viz3d myWindow("Coordinate Frame");
38 
39     /// Add coordinate axes
40     myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
41 
42     /// Add line to represent (1,1,1) axis
43     viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f));
44     axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
45     myWindow.showWidget("Line Widget", axis);
46 
47     /// Construct a cube widget
48     viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue());
49     cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
50     myWindow.showWidget("Cube Widget", cube_widget);
51 
52     /// Rodrigues vector
53     Mat rot_vec = Mat::zeros(1,3,CV_32F);
54     float translation_phase = 0.0, translation = 0.0;
55     while(!myWindow.wasStopped())
56     {
57         /* Rotation using rodrigues */
58         /// Rotate around (1,1,1)
59         rot_vec.at<float>(0,0) += CV_PI * 0.01f;
60         rot_vec.at<float>(0,1) += CV_PI * 0.01f;
61         rot_vec.at<float>(0,2) += CV_PI * 0.01f;
62 
63         /// Shift on (1,1,1)
64         translation_phase += CV_PI * 0.01f;
65         translation = sin(translation_phase);
66 
67         Mat rot_mat;
68         Rodrigues(rot_vec, rot_mat);
69 
70         /// Construct pose
71         Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
72 
73         myWindow.setWidgetPose("Cube Widget", pose);
74 
75         myWindow.spinOnce(1, true);
76     }
77 
78     return 0;
79 }
80