Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-template-tracker.cpp
1
2#include <visp3/core/vpConfig.h>
3#include <visp3/gui/vpDisplayFactory.h>
4#include <visp3/io/vpVideoReader.h>
6#include <visp3/tt/vpTemplateTrackerSSDInverseCompositional.h>
7#include <visp3/tt/vpTemplateTrackerWarpHomography.h>
9
10int main(int argc, char **argv)
11{
12#if defined(VISP_HAVE_OPENCV)
13#ifdef ENABLE_VISP_NAMESPACE
14 using namespace VISP_NAMESPACE_NAME;
15#endif
16 std::string opt_videoname = "bruegel.mp4";
17 unsigned int opt_subsample = 1;
18
19 for (int i = 1; i < argc; i++) {
20 if (std::string(argv[i]) == "--videoname" && i + 1 < argc) {
21 opt_videoname = std::string(argv[++i]);
22 }
23 else if (std::string(argv[i]) == "--subsample" && i + 1 < argc) {
24 opt_subsample = static_cast<unsigned int>(std::atoi(argv[++i]));
25 }
26 else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
27 std::cout << "\nUsage: " << argv[0]
28 << " [--videoname <video name>]"
29 << " [--subsample <scale factor>] [--help] [-h]\n"
30 << std::endl;
31 return EXIT_SUCCESS;
32 }
33 }
34
35 std::cout << "Video name: " << opt_videoname << std::endl;
36
38
40 g.setFileName(opt_videoname);
41 g.open(Iacq);
42 Iacq.subsample(opt_subsample, opt_subsample, I);
43
44#if defined(VISP_HAVE_DISPLAY)
45#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
46 std::shared_ptr<vpDisplay> display = vpDisplayFactory::createDisplay(I, 100, 100, "Template tracker", vpDisplay::SCALE_AUTO);
47#else
48 vpDisplay *display = vpDisplayFactory::allocateDisplay(I, 100, 100, "Template tracker", vpDisplay::SCALE_AUTO);
49#endif
50#else
51 std::cout << "No image viewer is available..." << std::endl;
52#endif
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
101#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11) && defined(VISP_HAVE_DISPLAY)
102 if (display != nullptr) {
103 delete display;
104 }
105#endif
106#else
107 (void)argc;
108 (void)argv;
109#endif
110}
Implementation of column vector and the associated operations.
static const vpColor red
Definition vpColor.h:198
Class that defines generic functionalities for display.
Definition vpDisplay.h:171
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)
unsigned int getDownScalingFactor()
Definition vpDisplay.h:218
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 of the vpImage class member functions.
Definition vpImage.h:131
void subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
Definition vpImage.h:755
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 open(vpImage< vpRGBa > &I) VP_OVERRIDE
void setFileName(const std::string &filename)
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)