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:pt: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);
122 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
bool &pyramidal,
123 WarpType &warp_type, TrackerType &tracker_type,
long &last_frame);
125 void usage(
const char *name,
const char *badparam,
const WarpType &warp_type, TrackerType &tracker_type,
126 const long &last_frame)
129 Example of template tracking.\n\
132 %s [-i <test image path>] [-c] [-d] [-p] \n\
133 [-w <warp type>] [-t <tracker type>] \n\
134 [-l <last frame number>] [-h]\n", name);
138 -i <input image path> \n\
139 Set image input path.\n\
140 From this path read images \n\
141 \"cube/image%%04d.pgm\". These \n\
142 images come from ViSP-images-x.y.z.tar.gz available \n\
143 on the ViSP website.\n\
144 Setting the VISP_INPUT_IMAGE_PATH environment\n\
145 variable produces the same behaviour than using\n\
148 -l <last frame number> %ld\n\
149 Last frame number to consider.\n\
152 Turn off the display.\n\
155 Disable the mouse click. Useful to automaze the \n\
156 execution of this program without humain intervention.\n\
159 #ifdef VISP_HAVE_MODULE_TT_MI
161 -w <warp type=[0,1,2,3,4,5]> %d\n\
162 Set the model used to warp the template. \n\
163 Authorized values are:\n\
166 %d : Homography in SL3\n\
167 %d : SRT (scale, rotation, translation)\n\
168 %d : RT (rotation, translation)\n\
169 %d : Translation\n\n", (
int)warp_type, (
int)WARP_AFFINE, (
int)WARP_HOMOGRAPHY, (
int)WARP_HOMOGRAPHY_SL3, (
int)WARP_SRT,
170 (
int)WARP_TRANSLATION, (
int)WARP_RT);
173 -w <warp type=[0,1,2,3,4]> %d\n\
174 Set the model used to warp the template. \n\
175 Authorized values are:\n\
178 %d : Homography in SL3\n\
179 %d : SRT (scale, rotation, translation)\n\
180 %d : Translation\n\n", (
int)warp_type, (
int)WARP_AFFINE, (
int)WARP_HOMOGRAPHY, (
int)WARP_HOMOGRAPHY_SL3, (
int)WARP_SRT,
181 (
int)WARP_TRANSLATION);
184 #ifdef VISP_HAVE_MODULE_TT_MI
186 -t <tracker type=[0,1,2,3,4,5,6,7,8,9]> %d\n\
187 Set the tracker used to track the template. \n\
188 Authorized values are:\n\
190 %d : SSD forward additional\n\
191 %d : SSD forward compositional\n\
192 %d : SSD inverse compositional\n\
193 %d : ZNCC forward additional\n\
194 %d : ZNCC inverse compositional\n\
196 %d : MI forward additional\n\
197 %d : MI forward compositional\n\
198 %d : MI inverse compositional\n\n", (
int)tracker_type, (
int)TRACKER_SSD_ESM, (
int)TRACKER_SSD_FORWARD_ADDITIONAL,
199 (
int)TRACKER_SSD_FORWARD_COMPOSITIONAL, (
int)TRACKER_SSD_INVERSE_COMPOSITIONAL,
200 (
int)TRACKER_ZNCC_FORWARD_ADDITIONEL, (
int)TRACKER_ZNCC_INVERSE_COMPOSITIONAL, (
int)TRACKER_MI_ESM,
201 (
int)TRACKER_MI_FORWARD_ADDITIONAL, (
int)TRACKER_MI_FORWARD_COMPOSITIONAL,
202 (
int)TRACKER_MI_INVERSE_COMPOSITIONAL);
205 -t <tracker type=[0,1,2,3,4,5]> %d\n\
206 Set the tracker used to track the template. \n\
207 Authorized values are:\n\
209 %d : SSD forward additional\n\
210 %d : SSD forward compositional\n\
211 %d : SSD inverse compositional\n\
212 %d : ZNCC forward additional\n\
213 %d : ZNCC inverse compositional\n\n", (
int)tracker_type, (
int)TRACKER_SSD_ESM, (
int)TRACKER_SSD_FORWARD_ADDITIONAL,
214 (
int)TRACKER_SSD_FORWARD_COMPOSITIONAL, (
int)TRACKER_SSD_INVERSE_COMPOSITIONAL,
215 (
int)TRACKER_ZNCC_FORWARD_ADDITIONEL, (
int)TRACKER_ZNCC_INVERSE_COMPOSITIONAL);
220 Enable pyramidal tracking.\n\
223 Print the help.\n\n");
226 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
229 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
bool &pyramidal,
230 WarpType &warp_type, TrackerType &tracker_type,
long &last_frame)
238 click_allowed =
false;
244 usage(argv[0], NULL, warp_type, tracker_type, last_frame);
251 last_frame = (long)atoi(optarg_);
257 tracker_type = (TrackerType)atoi(optarg_);
260 warp_type = (WarpType)atoi(optarg_);
264 usage(argv[0], optarg_, warp_type, tracker_type, last_frame);
270 if (warp_type >= WARP_LAST) {
271 usage(argv[0], NULL, warp_type, tracker_type, last_frame);
272 std::cerr <<
"ERROR: " << std::endl;
273 std::cerr <<
" Bad argument -w <warp type> with \"warp type\"=" << (int)warp_type << std::endl << std::endl;
276 if (tracker_type >= TRACKER_LAST) {
277 usage(argv[0], NULL, warp_type, tracker_type, last_frame);
278 std::cerr <<
"ERROR: " << std::endl;
279 std::cerr <<
" Bad argument -t <tracker type> with \"tracker type\"=" << (int)tracker_type << std::endl
283 if ((c == 1) || (c == -1)) {
285 usage(argv[0], NULL, warp_type, tracker_type, last_frame);
286 std::cerr <<
"ERROR: " << std::endl;
287 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
294 int main(
int argc,
const char **argv)
297 std::string env_ipath;
298 std::string opt_ipath;
300 bool opt_click_allowed =
true;
301 bool opt_display =
true;
302 bool opt_pyramidal =
false;
303 TrackerType opt_tracker_type = TRACKER_SSD_INVERSE_COMPOSITIONAL;
304 WarpType opt_warp_type = WARP_AFFINE;
305 long opt_last_frame = 30;
312 if (!env_ipath.empty())
316 if (!getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display, opt_pyramidal, opt_warp_type,
317 opt_tracker_type, opt_last_frame)) {
322 if (opt_ipath.empty() && env_ipath.empty()) {
323 usage(argv[0], NULL, opt_warp_type, opt_tracker_type, opt_last_frame);
324 std::cerr << std::endl <<
"ERROR:" << std::endl;
325 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
326 <<
" environment variable to specify the location of the " << std::endl
327 <<
" image path where test images are located." << std::endl
334 if (!opt_ipath.empty())
348 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
356 #if defined VISP_HAVE_X11
358 #elif defined VISP_HAVE_GDI
360 #elif defined VISP_HAVE_OPENCV
362 #elif defined VISP_HAVE_D3D9
364 #elif defined VISP_HAVE_GTK
369 #if defined(VISP_HAVE_DISPLAY)
370 display->init(I, 100, 100,
"Test tracking");
377 switch (opt_warp_type) {
381 case WARP_HOMOGRAPHY:
384 case WARP_HOMOGRAPHY_SL3:
390 case WARP_TRANSLATION:
393 #ifdef VISP_HAVE_MODULE_TT_MI
403 switch (opt_tracker_type) {
404 case TRACKER_SSD_ESM:
407 case TRACKER_SSD_FORWARD_ADDITIONAL:
410 case TRACKER_SSD_FORWARD_COMPOSITIONAL:
413 case TRACKER_SSD_INVERSE_COMPOSITIONAL:
416 case TRACKER_ZNCC_FORWARD_ADDITIONEL:
419 case TRACKER_ZNCC_INVERSE_COMPOSITIONAL:
422 #ifdef VISP_HAVE_MODULE_TT_MI
426 case TRACKER_MI_FORWARD_ADDITIONAL:
429 case TRACKER_MI_FORWARD_COMPOSITIONAL:
432 case TRACKER_MI_INVERSE_COMPOSITIONAL:
447 bool delaunay =
false;
448 if (opt_display && opt_click_allowed)
451 std::vector<vpImagePoint> v_ip;
469 while (!reader.
end()) {
472 std::cout <<
"Process image number " << reader.
getFrameIndex() << std::endl;
480 std::cout <<
"re-init simulation" << std::endl;
481 if (opt_click_allowed)
486 if (opt_display && opt_click_allowed) {
491 std::vector<vpImagePoint> v_ip;
517 warp_->
warpZone(zoneRef_, p_, zoneWarped_);
524 if (opt_click_allowed) {
538 std::cout <<
"Catch an exception: " << e << std::endl;
547 std::cout <<
"visp_tt module or display not available." << std::endl;