48 #include <visp3/core/vpConfig.h> 50 #if defined(VISP_HAVE_MODULE_TT) && defined(VISP_HAVE_DISPLAY) 52 #include <visp3/core/vpDebug.h> 53 #include <visp3/core/vpHomogeneousMatrix.h> 54 #include <visp3/core/vpIoTools.h> 55 #include <visp3/core/vpMath.h> 56 #include <visp3/gui/vpDisplayD3D.h> 57 #include <visp3/gui/vpDisplayGDI.h> 58 #include <visp3/gui/vpDisplayGTK.h> 59 #include <visp3/gui/vpDisplayOpenCV.h> 60 #include <visp3/gui/vpDisplayX.h> 61 #include <visp3/io/vpImageIo.h> 62 #include <visp3/io/vpParseArgv.h> 63 #include <visp3/io/vpVideoReader.h> 65 #include <visp3/tt/vpTemplateTrackerSSD.h> 66 #include <visp3/tt/vpTemplateTrackerSSDESM.h> 67 #include <visp3/tt/vpTemplateTrackerSSDForwardAdditional.h> 68 #include <visp3/tt/vpTemplateTrackerSSDForwardCompositional.h> 69 #include <visp3/tt/vpTemplateTrackerSSDInverseCompositional.h> 70 #include <visp3/tt/vpTemplateTrackerZNCCForwardAdditional.h> 71 #include <visp3/tt/vpTemplateTrackerZNCCInverseCompositional.h> 73 #include <visp3/tt/vpTemplateTrackerWarpAffine.h> 74 #include <visp3/tt/vpTemplateTrackerWarpHomography.h> 75 #include <visp3/tt/vpTemplateTrackerWarpHomographySL3.h> 76 #include <visp3/tt/vpTemplateTrackerWarpRT.h> 77 #include <visp3/tt/vpTemplateTrackerWarpSRT.h> 78 #include <visp3/tt/vpTemplateTrackerWarpTranslation.h> 80 #ifdef VISP_HAVE_MODULE_TT_MI 81 #include <visp3/tt_mi/vpTemplateTrackerMIESM.h> 82 #include <visp3/tt_mi/vpTemplateTrackerMIForwardAdditional.h> 83 #include <visp3/tt_mi/vpTemplateTrackerMIForwardCompositional.h> 84 #include <visp3/tt_mi/vpTemplateTrackerMIInverseCompositional.h> 87 #define GETOPTARGS "cdhi:l:Lprs:t:w:" 89 #ifndef DOXYGEN_SHOULD_SKIP_THIS 96 #ifdef VISP_HAVE_MODULE_TT_MI 104 TRACKER_SSD_FORWARD_ADDITIONAL,
105 TRACKER_SSD_FORWARD_COMPOSITIONAL,
106 TRACKER_SSD_INVERSE_COMPOSITIONAL,
107 TRACKER_ZNCC_FORWARD_ADDITIONEL,
108 TRACKER_ZNCC_INVERSE_COMPOSITIONAL,
109 #ifdef VISP_HAVE_MODULE_TT_MI 111 TRACKER_MI_FORWARD_ADDITIONAL,
112 TRACKER_MI_FORWARD_COMPOSITIONAL,
113 TRACKER_MI_INVERSE_COMPOSITIONAL,
120 void usage(
const char *name,
const char *badparam,
const WarpType &warp_type, TrackerType &tracker_type,
121 const long &last_frame,
const double &residual_threhold)
124 Example of template tracking.\n\ 127 %s [-i <test image path>] [-c] [-d] [-p] \n\ 128 [-w <warp type>] [-t <tracker type>] \n\ 129 [-l <last frame number>] [-r] [-L] [-h]\n", name);
133 -i <input image path> \n\ 134 Set image input path.\n\ 135 From this path read images \n\ 136 \"cube/image%%04d.pgm\". These \n\ 137 images come from ViSP-images-x.y.z.tar.gz available \n\ 138 on the ViSP website.\n\ 139 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 140 variable produces the same behaviour than using\n\ 143 -l <last frame number> %ld\n\ 144 Last frame number to consider.\n\ 147 Turn off the display.\n\ 150 Disable the mouse click. Useful to automaze the \n\ 151 execution of this program without humain intervention.\n\ 154 #ifdef VISP_HAVE_MODULE_TT_MI 156 -w <warp type=[0,1,2,3,4,5]> %d\n\ 157 Set the model used to warp the template. \n\ 158 Authorized values are:\n\ 161 %d : Homography in SL3\n\ 162 %d : SRT (scale, rotation, translation)\n\ 164 %d : RT (rotation, translation)\n\n", (
int)warp_type, (
int)WARP_AFFINE, (
int)WARP_HOMOGRAPHY, (
int)WARP_HOMOGRAPHY_SL3, (
int)WARP_SRT,
165 (
int)WARP_TRANSLATION, (
int)WARP_RT);
168 -w <warp type=[0,1,2,3,4]> %d\n\ 169 Set the model used to warp the template. \n\ 170 Authorized values are:\n\ 173 %d : Homography in SL3\n\ 174 %d : SRT (scale, rotation, translation)\n\ 175 %d : Translation\n\n", (
int)warp_type, (
int)WARP_AFFINE, (
int)WARP_HOMOGRAPHY, (
int)WARP_HOMOGRAPHY_SL3, (
int)WARP_SRT,
176 (
int)WARP_TRANSLATION);
179 #ifdef VISP_HAVE_MODULE_TT_MI 181 -t <tracker type=[0,1,2,3,4,5,6,7,8,9]> %d\n\ 182 Set the tracker used to track the template. \n\ 183 Authorized values are:\n\ 185 %d : SSD forward additional\n\ 186 %d : SSD forward compositional\n\ 187 %d : SSD inverse compositional\n\ 188 %d : ZNCC forward additional\n\ 189 %d : ZNCC inverse compositional\n\ 191 %d : MI forward additional\n\ 192 %d : MI forward compositional\n\ 193 %d : MI inverse compositional\n", (
int)tracker_type, (
int)TRACKER_SSD_ESM, (
int)TRACKER_SSD_FORWARD_ADDITIONAL,
194 (
int)TRACKER_SSD_FORWARD_COMPOSITIONAL, (
int)TRACKER_SSD_INVERSE_COMPOSITIONAL,
195 (
int)TRACKER_ZNCC_FORWARD_ADDITIONEL, (
int)TRACKER_ZNCC_INVERSE_COMPOSITIONAL, (
int)TRACKER_MI_ESM,
196 (
int)TRACKER_MI_FORWARD_ADDITIONAL, (
int)TRACKER_MI_FORWARD_COMPOSITIONAL,
197 (
int)TRACKER_MI_INVERSE_COMPOSITIONAL);
200 -t <tracker type=[0,1,2,3,4,5]> %d\n\ 201 Set the tracker used to track the template. \n\ 202 Authorized values are:\n\ 204 %d : SSD forward additional\n\ 205 %d : SSD forward compositional\n\ 206 %d : SSD inverse compositional\n\ 207 %d : ZNCC forward additional\n\ 208 %d : ZNCC inverse compositional\n", (
int)tracker_type, (
int)TRACKER_SSD_ESM, (
int)TRACKER_SSD_FORWARD_ADDITIONAL,
209 (
int)TRACKER_SSD_FORWARD_COMPOSITIONAL, (
int)TRACKER_SSD_INVERSE_COMPOSITIONAL,
210 (
int)TRACKER_ZNCC_FORWARD_ADDITIONEL, (
int)TRACKER_ZNCC_INVERSE_COMPOSITIONAL);
215 Enable pyramidal tracking.\n\ 218 Disable re-init at frame 10.\n\ 220 -s <residual threshold> %g\n\ 221 Threshold used to stop optimization when residual difference\n\ 222 between two successive optimization iteration becomes lower\n\ 223 that this parameter.\n\ 229 Print the help.\n\n", residual_threhold);
232 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
235 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
bool &pyramidal,
236 WarpType &warp_type, TrackerType &tracker_type,
long &last_frame,
bool &reinit,
double &threshold_residual,
245 click_allowed =
false;
251 usage(argv[0], NULL, warp_type, tracker_type, last_frame, threshold_residual);
258 last_frame = (long)atoi(optarg_);
270 tracker_type = (TrackerType)atoi(optarg_);
273 warp_type = (WarpType)atoi(optarg_);
276 threshold_residual = std::atof(optarg_);
280 usage(argv[0], optarg_, warp_type, tracker_type, last_frame, threshold_residual);
286 if (warp_type >= WARP_LAST) {
287 usage(argv[0], NULL, warp_type, tracker_type, last_frame, threshold_residual);
288 std::cerr <<
"ERROR: " << std::endl;
289 std::cerr <<
" Bad argument -w <warp type> with \"warp type\"=" << (int)warp_type << std::endl << std::endl;
292 if (tracker_type >= TRACKER_LAST) {
293 usage(argv[0], NULL, warp_type, tracker_type, last_frame, threshold_residual);
294 std::cerr <<
"ERROR: " << std::endl;
295 std::cerr <<
" Bad argument -t <tracker type> with \"tracker type\"=" << (int)tracker_type << std::endl
299 if ((c == 1) || (c == -1)) {
301 usage(argv[0], NULL, warp_type, tracker_type, last_frame, threshold_residual);
302 std::cerr <<
"ERROR: " << std::endl;
303 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
310 int main(
int argc,
const char **argv)
313 std::string env_ipath;
314 std::string opt_ipath;
316 bool opt_click_allowed =
true;
317 bool opt_display =
true;
318 bool opt_pyramidal =
false;
319 TrackerType opt_tracker_type = TRACKER_SSD_INVERSE_COMPOSITIONAL;
320 WarpType opt_warp_type = WARP_AFFINE;
321 long opt_last_frame = 30;
322 bool opt_reinit =
true;
323 double opt_threshold_residual = 1e-4;
324 bool opt_log =
false;
328 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX 329 std::string opath =
"/tmp";
330 #elif defined(_WIN32) 331 std::string opath =
"C:\\temp";
335 std::string username;
343 if (!env_ipath.empty())
351 if (!getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display, opt_pyramidal, opt_warp_type,
352 opt_tracker_type, opt_last_frame, opt_reinit, opt_threshold_residual, opt_log)) {
357 if (opt_ipath.empty() && env_ipath.empty()) {
358 usage(argv[0], NULL, opt_warp_type, opt_tracker_type, opt_last_frame, opt_threshold_residual);
359 std::cerr << std::endl <<
"ERROR:" << std::endl;
360 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
361 <<
" environment variable to specify the location of the " << std::endl
362 <<
" image path where test images are located." << std::endl
369 if (!opt_ipath.empty())
375 ofs.open( logfilename.c_str() );
387 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
395 #if defined VISP_HAVE_X11 397 #elif defined VISP_HAVE_GDI 399 #elif defined VISP_HAVE_OPENCV 401 #elif defined VISP_HAVE_D3D9 403 #elif defined VISP_HAVE_GTK 408 #if defined(VISP_HAVE_DISPLAY) 409 display->init(I, 100, 100,
"Test tracking");
416 switch (opt_warp_type) {
420 case WARP_HOMOGRAPHY:
423 case WARP_HOMOGRAPHY_SL3:
429 case WARP_TRANSLATION:
432 #ifdef VISP_HAVE_MODULE_TT_MI 442 switch (opt_tracker_type) {
443 case TRACKER_SSD_ESM:
446 case TRACKER_SSD_FORWARD_ADDITIONAL:
449 case TRACKER_SSD_FORWARD_COMPOSITIONAL:
452 case TRACKER_SSD_INVERSE_COMPOSITIONAL:
455 case TRACKER_ZNCC_FORWARD_ADDITIONEL:
458 case TRACKER_ZNCC_INVERSE_COMPOSITIONAL:
461 #ifdef VISP_HAVE_MODULE_TT_MI 465 case TRACKER_MI_FORWARD_ADDITIONAL:
468 case TRACKER_MI_FORWARD_COMPOSITIONAL:
471 case TRACKER_MI_INVERSE_COMPOSITIONAL:
487 bool delaunay =
false;
488 if (opt_display && opt_click_allowed)
491 std::vector<vpImagePoint> v_ip;
512 while (!reader.
end()) {
515 std::cout <<
"Process image number " << reader.
getFrameIndex() << std::endl;
527 std::cout <<
"re-init simulation" << std::endl;
528 if (opt_click_allowed)
533 if (opt_display && opt_click_allowed) {
538 std::vector<vpImagePoint> v_ip;
564 warp_->
warpZone(zoneRef_, p_, zoneWarped_);
574 std::cout <<
"Total time: " << t_end - t_init <<
" ms" << std::endl;
575 std::cout <<
"Total mean: " << (t_end - t_init)/niter <<
" ms" << std::endl;
578 std::cout <<
"Log are saved in: " << logfilename << std::endl;
582 if (opt_click_allowed) {
596 std::cout <<
"Catch an exception: " << e << std::endl;
605 std::cout <<
"visp_tt module or display not available." << std::endl;
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, unsigned int thickness=3)
void setSampling(int sample_i, int sample_j)
Class that defines generic functionnalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
unsigned int getNbIteration() const
Display for windows using GDI (available on any windows 32 platform).
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
error that can be emited by ViSP classes.
void setIterationMax(const unsigned int &n)
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void open(vpImage< vpRGBa > &I)
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, unsigned int thickness=3)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
vpTemplateTrackerWarp * getWarp() const
void initClick(const vpImage< unsigned char > &I, bool delaunay=false)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void acquire(vpImage< vpRGBa > &I)
void initFromPoints(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &v_ip, bool delaunay=false)
void warpZone(const vpTemplateTrackerZone &in, const vpColVector &p, vpTemplateTrackerZone &out)
long getFrameIndex() const
void set_ij(double ii, double jj)
void setLastFrameIndex(const long last_frame)
Implementation of column vector and the associated operations.
void track(const vpImage< unsigned char > &I)
void setFileName(const std::string &filename)
void setFirstFrameIndex(const long first_frame)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void setThresholdResidualDifference(double threshold)
vpTemplateTrackerZone getZoneRef() const
void setPyramidal(unsigned int nlevels=2, unsigned int level_to_stop=1)
void setThresholdGradient(double threshold)