OpenCV  3.0.0-rc1
Open Source Computer Vision
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Pose of a widget

Goal

In this tutorial you will learn how to

Code

You can download the code from here.

1 
7 #include <opencv2/viz.hpp>
8 #include <opencv2/calib3d.hpp>
9 #include <iostream>
10 
11 using namespace cv;
12 using namespace std;
13 
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 
32 int main()
33 {
34  help();
35 
37  viz::Viz3d myWindow("Coordinate Frame");
38 
40  myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
41 
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 
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 
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 */
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 
64  translation_phase += CV_PI * 0.01f;
65  translation = sin(translation_phase);
66 
67  Mat rot_mat;
68  Rodrigues(rot_vec, rot_mat);
69 
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 }
void Rodrigues(InputArray src, OutputArray dst, OutputArray jacobian=noArray())
Converts a rotation matrix to a rotation vector or vice versa.
__device__ __forceinline__ float1 sin(const uchar1 &a)
Definition: vec_math.hpp:285
static Color blue()
Point3_< float > Point3f
Definition: types.hpp:247
static MatExpr zeros(int rows, int cols, int type)
Returns a zero array of the specified size and type.
Vec< float, 3 > Vec3f
Definition: matx.hpp:376
Definition: widgets.hpp:65
Compond widgets.
Definition: widgets.hpp:504
The Viz3d class represents a 3D visualizer window. This class is implicitly shared. :
Definition: viz3d.hpp:67
Simple widgets.
Definition: widgets.hpp:232
This 3D Widget defines a cube.
Definition: widgets.hpp:369
#define CV_32F
Definition: cvdef.h:106
int main(int argc, const char *argv[])
Definition: facerec_demo.cpp:67
_Tp & at(int i0=0)
Returns a reference to the specified array element.
Affine transform.
Definition: affine.hpp:61

Explanation

Here is the general structure of the program:

Results

Here is the result of the program.