Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
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
13int 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(HAVE_OPENCV_HIGHGUI)
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:223
Display for windows using GDI (available on any windows 32 platform).
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:132
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:59
const char * getMessage() const
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)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Definition vpImage.h:135
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:184
static std::string getParent(const std::string &pathname)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:77
VISP_EXPORT int wait(double t0, double t)