ViSP  2.9.0
tutorial-klt-tracker.cpp
1 
2 #include <visp/vpImageConvert.h>
3 #include <visp/vpKltOpencv.h>
4 #include <visp/vpDisplayOpenCV.h>
5 #include <visp/vpVideoReader.h>
6 
7 int main()
8 {
9 #if (VISP_HAVE_OPENCV_VERSION >= 0x010100) && defined(VISP_HAVE_FFMPEG)
10  try {
11  vpVideoReader reader;
12  reader.setFileName("video-postcard.mpeg");
13 
15  reader.acquire(I);
16 
17  IplImage * cvI = NULL;
19 
20  // Display initialisation
21  vpDisplayOpenCV d(I, 0, 0, "Klt tracking");
24 
25  vpKltOpencv tracker;
26  // Set tracker parameters
27  tracker.setMaxFeatures(200);
28  tracker.setWindowSize(10);
29  tracker.setQuality(0.01);
30  tracker.setMinDistance(15);
31  tracker.setHarrisFreeParameter(0.04);
32  tracker.setBlockSize(9);
33  tracker.setUseHarris(1);
34  tracker.setPyramidLevels(3);
35 
36  // Initialise the tracking
37  tracker.initTracking(cvI);
38 
39  while ( ! reader.end() )
40  {
41  reader.acquire(I);
43 
45  tracker.track(cvI);
46 
47  tracker.display(I, vpColor::red);
49  }
50 
52 
53  cvReleaseImage(&cvI);
54 
55  return 0;
56  }
57  catch(vpException e) {
58  std::cout << "Catch an exception: " << e << std::endl;
59  }
60 #endif
61 }
void setQuality(double input)
Definition: vpKltOpencv.h:264
void track(const IplImage *I)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void setUseHarris(const int input)
Definition: vpKltOpencv.h:273
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void display(const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1)
error that can be emited by ViSP classes.
Definition: vpException.h:76
void setPyramidLevels(const int input)
Definition: vpKltOpencv.h:263
void setBlockSize(const int input)
Definition: vpKltOpencv.h:219
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:1994
static const vpColor red
Definition: vpColor.h:167
void setWindowSize(const int input)
Definition: vpKltOpencv.h:274
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:206
The vpDisplayOpenCV allows to display image using the opencv library.
void acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
void initTracking(const IplImage *I, const IplImage *mask=NULL)
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV.
Definition: vpKltOpencv.h:103
virtual bool getClick(bool blocking=true)=0
void setMaxFeatures(const int input)
void setMinDistance(double input)
Definition: vpKltOpencv.h:243
void setHarrisFreeParameter(double input)
Definition: vpKltOpencv.h:227