Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-template-tracker.cpp
#include <visp3/core/vpConfig.h>
#include <visp3/gui/vpDisplayFactory.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)
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
std::string opt_videoname = "bruegel.mp4";
unsigned int opt_subsample = 1;
for (int i = 1; i < argc; i++) {
if (std::string(argv[i]) == "--videoname" && i + 1 < argc) {
opt_videoname = std::string(argv[++i]);
}
else if (std::string(argv[i]) == "--subsample" && i + 1 < argc) {
opt_subsample = static_cast<unsigned int>(std::atoi(argv[++i]));
}
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_DISPLAY)
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
std::shared_ptr<vpDisplay> display = vpDisplayFactory::createDisplay(I, 100, 100, "Template tracker", vpDisplay::SCALE_AUTO);
#else
vpDisplay *display = vpDisplayFactory::allocateDisplay(I, 100, 100, "Template tracker", vpDisplay::SCALE_AUTO);
#endif
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
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);
}
}
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11) && defined(VISP_HAVE_DISPLAY)
if (display != nullptr) {
delete display;
}
#endif
#else
(void)argc;
(void)argv;
#endif
}
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)