Visual Servoing Platform version 3.5.0
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
11int 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
31
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
46 display.setDownScalingFactor(vpDisplay::SCALE_AUTO);
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}
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
static const vpColor red
Definition: vpColor.h:217
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
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:183
unsigned int getDownScalingFactor()
Definition: vpDisplay.h:235
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:175
void subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
Definition: vpImage.h:1220
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()