Visual Servoing Platform version 3.5.0
tutorial-pose-from-points-image.cpp
1
2#include <visp3/io/vpImageIo.h>
3#include <visp3/gui/vpDisplayGDI.h>
4#include <visp3/gui/vpDisplayOpenCV.h>
5#include <visp3/gui/vpDisplayX.h>
6
8#include "pose_helper.h"
10
11int main()
12{
13 try {
16 vpImageIo::read(I, "square.pgm");
18
19#if defined(VISP_HAVE_X11)
20 vpDisplayX d(I);
21#elif defined(VISP_HAVE_GDI)
22 vpDisplayGDI d(I);
23#elif defined(VISP_HAVE_OPENCV)
24 vpDisplayOpenCV d(I);
25#endif
26
28 vpCameraParameters cam(840, 840, I.getWidth() / 2, I.getHeight() / 2);
31 std::vector<vpDot2> dot(4);
32 std::vector<vpImagePoint> ip(4);
33 dot[0].initTracking(I, vpImagePoint(193, 157));
34 dot[1].initTracking(I, vpImagePoint(203, 366));
35 dot[2].initTracking(I, vpImagePoint(313, 402));
36 dot[3].initTracking(I, vpImagePoint(304, 133));
39 std::vector<vpPoint> point;
40 point.push_back(vpPoint(-0.06, -0.06, 0));
41 point.push_back(vpPoint( 0.06, -0.06, 0));
42 point.push_back(vpPoint( 0.06, 0.06, 0));
43 point.push_back(vpPoint(-0.06, 0.06, 0));
45
49 bool init = true;
50
51 while (1) {
53 vpImageIo::read(I, "square.pgm");
55 for (unsigned int i = 0; i < dot.size(); i++) {
56 dot[i].setGraphics(true);
57 dot[i].track(I);
58 ip[i] = dot[i].getCog();
59 }
62 computePose(point, ip, cam, init, cMo);
65 vpDisplay::displayFrame(I, cMo, cam, 0.05, vpColor::none);
68
70 if (init)
71 init = false; // turn off pose initialisation
73
75 if (vpDisplay::getClick(I, false))
76 break;
78
80 vpTime::wait(40);
82 }
83 } catch (const vpException &e) {
84 std::cout << "Catch an exception: " << e.getMessage() << std::endl;
85 }
86}
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:90
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:149
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
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
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)