Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
tutorial-template-tracker.cpp
1 
2 #include <visp3/core/vpConfig.h>
3 #include <visp3/gui/vpDisplayGDI.h>
4 #include <visp3/gui/vpDisplayOpenCV.h>
5 #include <visp3/gui/vpDisplayX.h>
6 #include <visp3/io/vpVideoReader.h>
8 #include <visp3/tt/vpTemplateTrackerSSDInverseCompositional.h>
9 #include <visp3/tt/vpTemplateTrackerWarpHomography.h>
11 
12 int main(int argc, char **argv)
13 {
14 #if defined(VISP_HAVE_OPENCV)
15 #ifdef ENABLE_VISP_NAMESPACE
16  using namespace VISP_NAMESPACE_NAME;
17 #endif
18  std::string opt_videoname = "bruegel.mp4";
19  unsigned int opt_subsample = 1;
20 
21  for (int i = 0; i < argc; i++) {
22  if (std::string(argv[i]) == "--videoname")
23  opt_videoname = std::string(argv[i + 1]);
24  else if (std::string(argv[i]) == "--subsample")
25  opt_subsample = static_cast<unsigned int>(std::atoi(argv[i + 1]));
26  else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
27  std::cout << "\nUsage: " << argv[0] << " [--videoname <video name>] [--subsample <scale factor>] [--help] [-h]\n"
28  << std::endl;
29  return EXIT_SUCCESS;
30  }
31  }
32 
33  std::cout << "Video name: " << opt_videoname << std::endl;
34 
35  vpImage<unsigned char> I, Iacq;
36 
37  vpVideoReader g;
38  g.setFileName(opt_videoname);
39  g.open(Iacq);
40  Iacq.subsample(opt_subsample, opt_subsample, I);
41 
42 #if defined(VISP_HAVE_X11)
43  vpDisplayX display;
44 #elif defined(VISP_HAVE_GDI)
45  vpDisplayGDI display;
46 #elif defined(HAVE_OPENCV_HIGHGUI)
47  vpDisplayOpenCV display;
48 #else
49  std::cout << "No image viewer is available..." << std::endl;
50 #endif
51  display.setDownScalingFactor(vpDisplay::SCALE_AUTO);
52  display.init(I, 100, 100, "Template tracker");
55 
60 
61  tracker.setSampling(2, 2);
62  tracker.setLambda(0.001);
63  tracker.setIterationMax(200);
64  tracker.setPyramidal(2, 1);
65 
67  tracker.initClick(I);
69 
70  while (1) {
71  double t = vpTime::measureTimeMs();
72  g.acquire(Iacq);
73  Iacq.subsample(opt_subsample, opt_subsample, I);
75 
77  tracker.track(I);
79 
81  vpColVector p = tracker.getp();
82  vpHomography H = warp.getHomography(p);
83  std::cout << "Homography: \n" << H << std::endl;
85 
87  tracker.display(I, vpColor::red);
89 
91  "Click to quit", vpColor::red);
92  if (vpDisplay::getClick(I, false))
93  break;
94 
96  if (!g.isVideoFormat()) {
97  vpTime::wait(t, 40);
98 }
99 }
100 #else
101  (void)argc;
102  (void)argv;
103 #endif
104 }
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
static const vpColor red
Definition: vpColor.h:217
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:130
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)
@ SCALE_AUTO
Definition: vpDisplay.h:184
unsigned int getDownScalingFactor()
Definition: vpDisplay.h:221
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:174
void subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
Definition: vpImage.h:749
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)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()