ViSP  2.8.0
tutorial-pose-from-points-image.cpp
1 
2 #include <visp/vpDisplayGDI.h>
3 #include <visp/vpDisplayX.h>
4 #include <visp/vpDot2.h>
5 #include <visp/vpImageIo.h>
6 #include <visp/vpPixelMeterConversion.h>
7 #include <visp/vpPose.h>
8 
9 void computePose(std::vector<vpPoint> &point, const std::vector<vpDot2> &dot,
10  const vpCameraParameters &cam, bool init, vpHomogeneousMatrix &cMo)
11 {
12  vpPose pose; double x=0, y=0;
13  for (unsigned int i=0; i < point.size(); i ++) {
14  vpPixelMeterConversion::convertPoint(cam, dot[i].getCog(), x, y);
15  point[i].set_x(x);
16  point[i].set_y(y);
17  pose.addPoint(point[i]);
18  }
19 
20  if (init == true) pose.computePose(vpPose::DEMENTHON_VIRTUAL_VS, cMo);
21  else pose.computePose(vpPose::VIRTUAL_VS, cMo) ;
22 }
23 
24 int main()
25 {
27  vpImageIo::read(I, "square.pgm");
28 
29 #if defined(VISP_HAVE_X11)
30  vpDisplayX d(I);
31 #elif defined(VISP_HAVE_GDI)
32  vpDisplayGDI d(I);
33 #endif
34 
35  vpCameraParameters cam(840, 840, I.getWidth()/2, I.getHeight()/2);
36  std::vector<vpDot2> dot(4);
37  dot[0].initTracking(I, vpImagePoint(193, 157));
38  dot[1].initTracking(I, vpImagePoint(203, 366));
39  dot[2].initTracking(I, vpImagePoint(313, 402));
40  dot[3].initTracking(I, vpImagePoint(304, 133));
41  std::vector<vpPoint> point(4);
42  point[0].setWorldCoordinates(-0.06, -0.06, 0);
43  point[1].setWorldCoordinates( 0.06, -0.06, 0);
44  point[2].setWorldCoordinates( 0.06, 0.06, 0);
45  point[3].setWorldCoordinates(-0.06, 0.06, 0);
47  bool init = true;
48 
49  while(1){
50  vpImageIo::read(I, "square.pgm");
52  for (unsigned int i=0; i < dot.size(); i ++) {
53  dot[i].setGraphics(true);
54  dot[i].track(I);
55  }
56  computePose(point, dot, cam, init, cMo);
57  vpDisplay::displayFrame(I, cMo, cam, 0.05, vpColor::none);
59 
60  if (init) init = false; // turn off pose initialisation
61 
62  if (vpDisplay::getClick(I, false)) break;
63 
64  vpTime::wait(40);
65  }
66 }
unsigned int getWidth() const
Definition: vpImage.h:159
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:133
Define the X11 console to display images.
Definition: vpDisplayX.h:152
static const vpColor none
Definition: vpColor.h:179
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
static int wait(double t0, double t)
Definition: vpTime.cpp:149
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:1991
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:203
Class used for pose computation from N points (pose from point only).
Definition: vpPose.h:78
Generic class defining intrinsic camera parameters.
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness=1)
Definition: vpDisplay.cpp:368
unsigned int getHeight() const
Definition: vpImage.h:150
void computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo)
compute the pose for a given method
Definition: vpPose.cpp:382
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
static void read(vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:277
void addPoint(const vpPoint &P)
Add a new point in this array.
Definition: vpPose.cpp:150