Visual Servoing Platform  version 3.4.1 under development (2021-10-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 opt_videoname = "bruegel.mp4";
15  unsigned int opt_subsample = 1;
16 
17  for (int i = 0; i < argc; i++) {
18  if (std::string(argv[i]) == "--videoname")
19  opt_videoname = std::string(argv[i + 1]);
20  else if (std::string(argv[i]) == "--subsample")
21  opt_subsample = static_cast<unsigned int>(std::atoi(argv[i + 1]));
22  else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
23  std::cout << "\nUsage: " << argv[0] << " [--videoname <video name>] [--subsample <scale factor>] [--help] [-h]\n" << std::endl;
24  return 0;
25  }
26  }
27 
28  std::cout << "Video name: " << opt_videoname << std::endl;
29 
30  vpImage<unsigned char> I, Iacq;
31 
32  vpVideoReader g;
33  g.setFileName(opt_videoname);
34  g.open(Iacq);
35  Iacq.subsample(opt_subsample, opt_subsample, I);
36 
37 #if defined(VISP_HAVE_X11)
38  vpDisplayX display;
39 #elif defined(VISP_HAVE_GDI)
40  vpDisplayGDI display;
41 #elif defined(VISP_HAVE_OPENCV)
42  vpDisplayOpenCV display;
43 #else
44  std::cout << "No image viewer is available..." << std::endl;
45 #endif
47  display.init(I, 100, 100, "Template tracker");
50 
55 
56  tracker.setSampling(2, 2);
57  tracker.setLambda(0.001);
58  tracker.setIterationMax(200);
59  tracker.setPyramidal(2, 1);
60 
62  tracker.initClick(I);
64 
65  while (1) {
66  double t = vpTime::measureTimeMs();
67  g.acquire(Iacq);
68  Iacq.subsample(opt_subsample, opt_subsample, I);
70 
72  tracker.track(I);
74 
76  vpColVector p = tracker.getp();
77  vpHomography H = warp.getHomography(p);
78  std::cout << "Homography: \n" << H << std::endl;
80 
82  tracker.display(I, vpColor::red);
84 
86  "Click to quit", vpColor::red);
87  if (vpDisplay::getClick(I, false))
88  break;
89 
91  if (! g.isVideoFormat()) {
92  vpTime::wait(t, 40);
93  }
94  }
95 #else
96  (void)argc;
97  (void)argv;
98 #endif
99 }
VISP_EXPORT int wait(double t0, double t)
Definition: vpTime.cpp:173
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
virtual void setDownScalingFactor(unsigned int scale)
Definition: vpDisplay.cpp:231
void subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
Definition: vpImage.h:1220
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
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)
VISP_EXPORT double measureTimeMs()
Definition: vpTime.cpp:126
static const vpColor red
Definition: vpColor.h:217
void open(vpImage< vpRGBa > &I)
Implementation of an homography and operations on homographies.
Definition: vpHomography.h:174
bool isVideoFormat() const
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
unsigned int getDownScalingFactor()
Definition: vpDisplay.h:235
void setFileName(const std::string &filename)
vpHomography getHomography(const vpColVector &ParamM) const