Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
tutorial-pose-from-points-image.cpp
1 
3 #include <visp3/core/vpConfig.h>
4 #include <visp3/core/vpIoTools.h>
5 #include <visp3/gui/vpDisplayGDI.h>
6 #include <visp3/gui/vpDisplayOpenCV.h>
7 #include <visp3/gui/vpDisplayX.h>
8 #include <visp3/io/vpImageIo.h>
9 
11 #include "pose_helper.h"
13 
14 int main(int, char *argv[])
15 {
16 #ifdef ENABLE_VISP_NAMESPACE
17  using namespace VISP_NAMESPACE_NAME;
18 #endif
19  try {
22  vpImageIo::read(I, vpIoTools::getParent(argv[0]) + "/data/square.pgm");
24 
25 #if defined(VISP_HAVE_X11)
26  vpDisplayX d(I);
27 #elif defined(VISP_HAVE_GDI)
28  vpDisplayGDI d(I);
29 #elif defined(HAVE_OPENCV_HIGHGUI)
30  vpDisplayOpenCV d(I);
31 #endif
32 
34  vpCameraParameters cam(840, 840, I.getWidth() / 2, I.getHeight() / 2);
37  std::vector<vpDot2> dot(4);
38  std::vector<vpImagePoint> ip(4);
39  dot[0].initTracking(I, vpImagePoint(193, 157));
40  dot[1].initTracking(I, vpImagePoint(203, 366));
41  dot[2].initTracking(I, vpImagePoint(313, 402));
42  dot[3].initTracking(I, vpImagePoint(304, 133));
45  std::vector<vpPoint> point;
46  point.push_back(vpPoint(-0.06, -0.06, 0));
47  point.push_back(vpPoint(0.06, -0.06, 0));
48  point.push_back(vpPoint(0.06, 0.06, 0));
49  point.push_back(vpPoint(-0.06, 0.06, 0));
51 
55  bool init = true;
56 
57  while (1) {
59  vpImageIo::read(I, vpIoTools::getParent(argv[0]) + "/data/square.pgm");
61  for (unsigned int i = 0; i < dot.size(); i++) {
62  dot[i].setGraphics(true);
63  dot[i].track(I);
64  ip[i] = dot[i].getCog();
65  }
68  computePose(point, ip, cam, init, cMo);
71  vpDisplay::displayFrame(I, cMo, cam, 0.05, vpColor::none);
74 
76  if (init)
77  init = false; // turn off pose initialisation
79 
81  if (vpDisplay::getClick(I, false))
82  break;
84 
86  vpTime::wait(40);
88  }
89  }
90  catch (const vpException &e) {
91  std::cout << "Catch an exception: " << e.getMessage() << std::endl;
92  }
93 }
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:130
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(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), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
Definition: vpException.h:60
const char * getMessage() const
Definition: vpException.cpp:65
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:147
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
unsigned int getWidth() const
Definition: vpImage.h:242
unsigned int getHeight() const
Definition: vpImage.h:181
static std::string getParent(const std::string &pathname)
Definition: vpIoTools.cpp:1314
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:79
VISP_EXPORT int wait(double t0, double t)