Visual Servoing Platform  version 3.6.1 under development (2024-04-18)
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)
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"
24  << std::endl;
25  return EXIT_SUCCESS;
26  }
27  }
28 
29  std::cout << "Video name: " << opt_videoname << std::endl;
30 
31  vpImage<unsigned char> I, Iacq;
32 
33  vpVideoReader g;
34  g.setFileName(opt_videoname);
35  g.open(Iacq);
36  Iacq.subsample(opt_subsample, opt_subsample, I);
37 
38 #if defined(VISP_HAVE_X11)
40 #elif defined(VISP_HAVE_GDI)
42 #elif defined(HAVE_OPENCV_HIGHGUI)
44 #else
45  std::cout << "No image viewer is available..." << std::endl;
46 #endif
47  display.setDownScalingFactor(vpDisplay::SCALE_AUTO);
48  display.init(I, 100, 100, "Template tracker");
51 
56 
57  tracker.setSampling(2, 2);
58  tracker.setLambda(0.001);
59  tracker.setIterationMax(200);
60  tracker.setPyramidal(2, 1);
61 
63  tracker.initClick(I);
65 
66  while (1) {
67  double t = vpTime::measureTimeMs();
68  g.acquire(Iacq);
69  Iacq.subsample(opt_subsample, opt_subsample, I);
71 
73  tracker.track(I);
75 
77  vpColVector p = tracker.getp();
78  vpHomography H = warp.getHomography(p);
79  std::cout << "Homography: \n" << H << std::endl;
81 
83  tracker.display(I, vpColor::red);
85 
87  "Click to quit", vpColor::red);
88  if (vpDisplay::getClick(I, false))
89  break;
90 
92  if (!g.isVideoFormat()) {
93  vpTime::wait(t, 40);
94  }
95  }
96 #else
97  (void)argc;
98  (void)argv;
99 #endif
100 }
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
static const vpColor red
Definition: vpColor.h:211
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
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:128
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)
@ SCALE_AUTO
Definition: vpDisplay.h:179
unsigned int getDownScalingFactor()
Definition: vpDisplay.h:231
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Implementation of an homography and operations on homographies.
Definition: vpHomography.h:168
void subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
Definition: vpImage.h:1638
vpHomography getHomography(const vpColVector &ParamM) const
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
bool isVideoFormat() const
void acquire(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()