ViSP  2.10.0
tutorial-template-tracker.cpp
1 
2 #include <visp/vpDisplayGDI.h>
3 #include <visp/vpDisplayX.h>
4 #include <visp/vpDisplayOpenCV.h>
5 #include <visp/vpVideoReader.h>
7 #include <visp/vpTemplateTrackerSSDInverseCompositional.h>
8 #include <visp/vpTemplateTrackerWarpHomography.h>
10 
11 int main(int argc, char** argv)
12 {
13 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100) || defined(VISP_HAVE_FFMPEG)
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 }
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:132
Define the X11 console to display images.
Definition: vpDisplayX.h:152
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2232
static const vpColor red
Definition: vpColor.h:167
void open(vpImage< vpRGBa > &I)
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:178
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:210
The vpDisplayOpenCV allows to display image using the opencv library.
void acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
virtual bool getClick(bool blocking=true)=0
vpHomography getHomography(const vpColVector &ParamM) const