Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
tutorial-template-tracker.cpp
1 
2 #include <visp3/gui/vpDisplayGDI.h>
3 #include <visp3/gui/vpDisplayOpenCV.h>
4 #include <visp3/gui/vpDisplayX.h>
5 #include <visp3/io/vpVideoReader.h>
7 #include <visp3/tt/vpTemplateTrackerSSDInverseCompositional.h>
8 #include <visp3/tt/vpTemplateTrackerWarpHomography.h>
10 
11 int main(int argc, char **argv)
12 {
13 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
14  std::string videoname = "bruegel.mpg";
15 
16  for (int i = 0; i < argc; i++) {
17  if (std::string(argv[i]) == "--videoname")
18  videoname = std::string(argv[i + 1]);
19  else if (std::string(argv[i]) == "--help") {
20  std::cout << "\nUsage: " << argv[0] << " [--name <video name>] [--help]\n" << std::endl;
21  return 0;
22  }
23  }
24 
25  std::cout << "Video name: " << videoname << std::endl;
26 
28 
29  vpVideoReader g;
30  g.setFileName(videoname);
31  g.open(I);
32 
33 #if defined(VISP_HAVE_X11)
34  vpDisplayX display;
35 #elif defined(VISP_HAVE_GDI)
36  vpDisplayGDI display;
37 #elif defined(VISP_HAVE_OPENCV)
38  vpDisplayOpenCV display;
39 #else
40  std::cout << "No image viewer is available..." << std::endl;
41 #endif
42 
43  display.init(I, 100, 100, "Template tracker");
46 
51 
52  tracker.setSampling(2, 2);
53  tracker.setLambda(0.001);
54  tracker.setIterationMax(200);
55  tracker.setPyramidal(2, 1);
56 
58  tracker.initClick(I);
60 
61  while (1) {
62  g.acquire(I);
64 
66  tracker.track(I);
68 
70  vpColVector p = tracker.getp();
71  vpHomography H = warp.getHomography(p);
72  std::cout << "Homography: \n" << H << std::endl;
74 
76  tracker.display(I, vpColor::red);
78 
79  if (vpDisplay::getClick(I, false))
80  break;
81 
83  }
84 #else
85  (void)argc;
86  (void)argv;
87 #endif
88 }
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:150
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:179
void open(vpImage< vpRGBa > &I)
Implementation of an homography and operations on homographies.
Definition: vpHomography.h:174
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void acquire(vpImage< vpRGBa > &I)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
void setFileName(const std::string &filename)
vpHomography getHomography(const vpColVector &ParamM) const