Visual Servoing Platform  version 3.5.1 under development (2022-08-10)
tutorial-pose-from-points-image.cpp
1 
3 #include <visp3/core/vpIoTools.h>
4 #include <visp3/gui/vpDisplayGDI.h>
5 #include <visp3/gui/vpDisplayOpenCV.h>
6 #include <visp3/gui/vpDisplayX.h>
7 #include <visp3/io/vpImageIo.h>
8 
10 #include "pose_helper.h"
12 
13 int main(int, char *argv[])
14 {
15  try {
18  vpImageIo::read(I, vpIoTools::getParent(argv[0]) + "/data/square.pgm");
20 
21 #if defined(VISP_HAVE_X11)
22  vpDisplayX d(I);
23 #elif defined(VISP_HAVE_GDI)
24  vpDisplayGDI d(I);
25 #elif defined(VISP_HAVE_OPENCV)
26  vpDisplayOpenCV d(I);
27 #endif
28 
30  vpCameraParameters cam(840, 840, I.getWidth() / 2, I.getHeight() / 2);
33  std::vector<vpDot2> dot(4);
34  std::vector<vpImagePoint> ip(4);
35  dot[0].initTracking(I, vpImagePoint(193, 157));
36  dot[1].initTracking(I, vpImagePoint(203, 366));
37  dot[2].initTracking(I, vpImagePoint(313, 402));
38  dot[3].initTracking(I, vpImagePoint(304, 133));
41  std::vector<vpPoint> point;
42  point.push_back(vpPoint(-0.06, -0.06, 0));
43  point.push_back(vpPoint(0.06, -0.06, 0));
44  point.push_back(vpPoint(0.06, 0.06, 0));
45  point.push_back(vpPoint(-0.06, 0.06, 0));
47 
51  bool init = true;
52 
53  while (1) {
55  vpImageIo::read(I, vpIoTools::getParent(argv[0]) + "/data/square.pgm");
57  for (unsigned int i = 0; i < dot.size(); i++) {
58  dot[i].setGraphics(true);
59  dot[i].track(I);
60  ip[i] = dot[i].getCog();
61  }
64  computePose(point, ip, cam, init, cMo);
67  vpDisplay::displayFrame(I, cMo, cam, 0.05, vpColor::none);
70 
72  if (init)
73  init = false; // turn off pose initialisation
75 
77  if (vpDisplay::getClick(I, false))
78  break;
80 
82  vpTime::wait(40);
84  }
85  } catch (const vpException &e) {
86  std::cout << "Catch an exception: " << e.getMessage() << std::endl;
87  }
88 }
Generic class defining intrinsic camera parameters.
static const vpColor none
Definition: vpColor.h:229
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:135
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0))
error that can be emited by ViSP classes.
Definition: vpException.h:72
const char * getMessage() const
Definition: vpException.cpp:87
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:148
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:89
unsigned int getWidth() const
Definition: vpImage.h:246
unsigned int getHeight() const
Definition: vpImage.h:188
void init(unsigned int h, unsigned int w, Type value)
Definition: vpImage.h:631
static std::string getParent(const std::string &pathname)
Definition: vpIoTools.cpp:1620
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:82
VISP_EXPORT int wait(double t0, double t)