Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-template-tracker.cpp
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpVideoReader.h>
#include <visp3/tt/vpTemplateTrackerSSDInverseCompositional.h>
#include <visp3/tt/vpTemplateTrackerWarpHomography.h>
int main(int argc, char **argv)
{
#if defined(VISP_HAVE_OPENCV)
std::string opt_videoname = "bruegel.mp4";
unsigned int opt_subsample = 1;
for (int i = 0; i < argc; i++) {
if (std::string(argv[i]) == "--videoname")
opt_videoname = std::string(argv[i + 1]);
else if (std::string(argv[i]) == "--subsample")
opt_subsample = static_cast<unsigned int>(std::atoi(argv[i + 1]));
else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
std::cout << "\nUsage: " << argv[0] << " [--videoname <video name>] [--subsample <scale factor>] [--help] [-h]\n"
<< std::endl;
return EXIT_SUCCESS;
}
}
std::cout << "Video name: " << opt_videoname << std::endl;
g.setFileName(opt_videoname);
g.open(Iacq);
Iacq.subsample(opt_subsample, opt_subsample, I);
#if defined(VISP_HAVE_X11)
vpDisplayX display;
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI display;
#elif defined(HAVE_OPENCV_HIGHGUI)
vpDisplayOpenCV display;
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
display.setDownScalingFactor(vpDisplay::SCALE_AUTO);
display.init(I, 100, 100, "Template tracker");
tracker.setSampling(2, 2);
tracker.setLambda(0.001);
tracker.setIterationMax(200);
tracker.setPyramidal(2, 1);
tracker.initClick(I);
while (1) {
double t = vpTime::measureTimeMs();
g.acquire(Iacq);
Iacq.subsample(opt_subsample, opt_subsample, I);
tracker.track(I);
vpColVector p = tracker.getp();
std::cout << "Homography: \n" << H << std::endl;
tracker.display(I, vpColor::red);
"Click to quit", vpColor::red);
if (vpDisplay::getClick(I, false))
break;
if (!g.isVideoFormat()) {
vpTime::wait(t, 40);
}
}
#else
(void)argc;
(void)argv;
#endif
}
Implementation of column vector and the associated operations.
static const vpColor red
Definition vpColor.h:211
Display for windows using GDI (available on any windows 32 platform).
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:132
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:231
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:135
void subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
Definition vpImage.h:1466
vpHomography getHomography(const vpColVector &ParamM) const
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, unsigned int thickness=3)
void setIterationMax(const unsigned int &n)
void setPyramidal(unsigned int nlevels=2, unsigned int level_to_stop=1)
vpColVector getp() const
void track(const vpImage< unsigned char > &I)
void setLambda(double l)
void setSampling(int sample_i, int sample_j)
void initClick(const vpImage< unsigned char > &I, bool delaunay=false)
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 double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)