47 #include <visp3/core/vpConfig.h>
49 #if defined(VISP_HAVE_MODULE_TT) && defined (VISP_HAVE_DISPLAY)
51 #include <visp3/core/vpDebug.h>
52 #include <visp3/gui/vpDisplayD3D.h>
53 #include <visp3/gui/vpDisplayGTK.h>
54 #include <visp3/gui/vpDisplayGDI.h>
55 #include <visp3/gui/vpDisplayOpenCV.h>
56 #include <visp3/gui/vpDisplayX.h>
57 #include <visp3/core/vpHomogeneousMatrix.h>
58 #include <visp3/io/vpImageIo.h>
59 #include <visp3/core/vpIoTools.h>
60 #include <visp3/core/vpMath.h>
61 #include <visp3/io/vpVideoReader.h>
62 #include <visp3/io/vpParseArgv.h>
64 #include <visp3/tt/vpTemplateTrackerSSD.h>
65 #include <visp3/tt/vpTemplateTrackerSSDForwardAdditional.h>
66 #include <visp3/tt/vpTemplateTrackerSSDForwardCompositional.h>
67 #include <visp3/tt/vpTemplateTrackerSSDInverseCompositional.h>
68 #include <visp3/tt/vpTemplateTrackerSSDESM.h>
69 #include <visp3/tt/vpTemplateTrackerZNCCForwardAdditional.h>
70 #include <visp3/tt/vpTemplateTrackerZNCCInverseCompositional.h>
72 #include <visp3/tt/vpTemplateTrackerWarpAffine.h>
73 #include <visp3/tt/vpTemplateTrackerWarpHomography.h>
74 #include <visp3/tt/vpTemplateTrackerWarpHomographySL3.h>
75 #include <visp3/tt/vpTemplateTrackerWarpSRT.h>
76 #include <visp3/tt/vpTemplateTrackerWarpTranslation.h>
77 #include <visp3/tt/vpTemplateTrackerWarpRT.h>
79 #ifdef VISP_HAVE_MODULE_TT_MI
80 # include <visp3/tt_mi/vpTemplateTrackerMIESM.h>
81 # include <visp3/tt_mi/vpTemplateTrackerMIForwardAdditional.h>
82 # include <visp3/tt_mi/vpTemplateTrackerMIForwardCompositional.h>
83 # include <visp3/tt_mi/vpTemplateTrackerMIInverseCompositional.h>
86 #define GETOPTARGS "cdhi:l:pt:w:"
88 #ifndef DOXYGEN_SHOULD_SKIP_THIS
95 #ifdef VISP_HAVE_MODULE_TT_MI
103 TRACKER_SSD_FORWARD_ADDITIONAL,
104 TRACKER_SSD_FORWARD_COMPOSITIONAL,
105 TRACKER_SSD_INVERSE_COMPOSITIONAL,
106 TRACKER_ZNCC_FORWARD_ADDITIONEL,
107 TRACKER_ZNCC_INVERSE_COMPOSITIONAL,
108 #ifdef VISP_HAVE_MODULE_TT_MI
110 TRACKER_MI_FORWARD_ADDITIONAL,
111 TRACKER_MI_FORWARD_COMPOSITIONAL,
112 TRACKER_MI_INVERSE_COMPOSITIONAL,
119 void usage(
const char *name,
const char *badparam,
const WarpType &warp_type,
120 TrackerType &tracker_type,
const long &last_frame);
121 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
122 bool &pyramidal, WarpType &warp_type, TrackerType &tracker_type,
long &last_frame);
124 void usage(
const char *name,
const char *badparam,
const WarpType &warp_type,
125 TrackerType &tracker_type,
const long &last_frame)
128 Example of template tracking.\n\
131 %s [-i <test image path>] [-c] [-d] [-p] \n\
132 [-w <warp type>] [-t <tracker type>] \n\
133 [-l <last frame number>] [-h]\n", name );
137 -i <input image path> \n\
138 Set image input path.\n\
139 From this path read images \n\
140 \"ViSP-images/cube/image%%04d.pgm\". These \n\
141 images come from ViSP-images-x.y.z.tar.gz available \n\
142 on the ViSP website.\n\
143 Setting the VISP_INPUT_IMAGE_PATH environment\n\
144 variable produces the same behaviour than using\n\
147 -l <last frame number> %ld\n\
148 Last frame number to consider.\n\
151 Turn off the display.\n\
154 Disable the mouse click. Useful to automaze the \n\
155 execution of this program without humain intervention.\n\
158 #ifdef VISP_HAVE_MODULE_TT_MI
160 -w <warp type=[0,1,2,3,4,5]> %d\n\
161 Set the model used to warp the template. \n\
162 Authorized values are:\n\
165 %d : Homography in SL3\n\
166 %d : SRT (scale, rotation, translation)\n\
167 %d : RT (rotation, translation)\n\
168 %d : Translation\n\n",
169 (
int)warp_type, (
int)WARP_AFFINE, (
int)WARP_HOMOGRAPHY, (
int)WARP_HOMOGRAPHY_SL3, (
int)WARP_SRT, (
int)WARP_TRANSLATION, (
int)WARP_RT);
172 -w <warp type=[0,1,2,3,4]> %d\n\
173 Set the model used to warp the template. \n\
174 Authorized values are:\n\
177 %d : Homography in SL3\n\
178 %d : SRT (scale, rotation, translation)\n\
179 %d : Translation\n\n",
180 (
int)warp_type, (
int)WARP_AFFINE, (
int)WARP_HOMOGRAPHY, (
int)WARP_HOMOGRAPHY_SL3, (
int)WARP_SRT, (
int)WARP_TRANSLATION);
183 #ifdef VISP_HAVE_MODULE_TT_MI
185 -t <tracker type=[0,1,2,3,4,5,6,7,8,9]> %d\n\
186 Set the tracker used to track the template. \n\
187 Authorized values are:\n\
189 %d : SSD forward additional\n\
190 %d : SSD forward compositional\n\
191 %d : SSD inverse compositional\n\
192 %d : ZNCC forward additional\n\
193 %d : ZNCC inverse compositional\n\
195 %d : MI forward additional\n\
196 %d : MI forward compositional\n\
197 %d : MI inverse compositional\n\n",
199 (
int)TRACKER_SSD_ESM, (
int)TRACKER_SSD_FORWARD_ADDITIONAL, (
int)TRACKER_SSD_FORWARD_COMPOSITIONAL,
200 (
int)TRACKER_SSD_INVERSE_COMPOSITIONAL, (
int)TRACKER_ZNCC_FORWARD_ADDITIONEL,
201 (
int)TRACKER_ZNCC_INVERSE_COMPOSITIONAL,
202 (
int)TRACKER_MI_ESM, (
int)TRACKER_MI_FORWARD_ADDITIONAL, (
int)TRACKER_MI_FORWARD_COMPOSITIONAL,
203 (
int)TRACKER_MI_INVERSE_COMPOSITIONAL);
206 -t <tracker type=[0,1,2,3,4,5]> %d\n\
207 Set the tracker used to track the template. \n\
208 Authorized values are:\n\
210 %d : SSD forward additional\n\
211 %d : SSD forward compositional\n\
212 %d : SSD inverse compositional\n\
213 %d : ZNCC forward additional\n\
214 %d : ZNCC inverse compositional\n\n",
216 (
int)TRACKER_SSD_ESM, (
int)TRACKER_SSD_FORWARD_ADDITIONAL, (
int)TRACKER_SSD_FORWARD_COMPOSITIONAL,
217 (
int)TRACKER_SSD_INVERSE_COMPOSITIONAL, (
int)TRACKER_ZNCC_FORWARD_ADDITIONEL,
218 (
int)TRACKER_ZNCC_INVERSE_COMPOSITIONAL);
223 Enable pyramidal tracking.\n\
226 Print the help.\n\n");
229 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
233 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
234 bool &pyramidal, WarpType &warp_type, TrackerType &tracker_type,
long &last_frame)
241 case 'c': click_allowed =
false;
break;
242 case 'd': display =
false;
break;
243 case 'h': usage(argv[0], NULL, warp_type, tracker_type, last_frame);
return false;
break;
244 case 'i': ipath = optarg_;
break;
245 case 'l': last_frame = (long)atoi(optarg_);
break;
246 case 'p': pyramidal =
true;
break;
247 case 't': tracker_type = (TrackerType)atoi(optarg_);
break;
248 case 'w': warp_type = (WarpType)atoi(optarg_);
break;
251 usage(argv[0], optarg_, warp_type, tracker_type, last_frame);
256 if (warp_type >= WARP_LAST) {
257 usage(argv[0], NULL, warp_type, tracker_type, last_frame);
258 std::cerr <<
"ERROR: " << std::endl;
259 std::cerr <<
" Bad argument -w <warp type> with \"warp type\"=" << (int)warp_type << std::endl << std::endl;
262 if (tracker_type >= TRACKER_LAST) {
263 usage(argv[0], NULL, warp_type, tracker_type, last_frame);
264 std::cerr <<
"ERROR: " << std::endl;
265 std::cerr <<
" Bad argument -t <tracker type> with \"tracker type\"=" << (int)tracker_type << std::endl << std::endl;
268 if ((c == 1) || (c == -1)) {
270 usage(argv[0], NULL, warp_type, tracker_type, last_frame);
271 std::cerr <<
"ERROR: " << std::endl;
272 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
280 main(
int argc,
const char ** argv)
283 std::string env_ipath;
284 std::string opt_ipath;
286 bool opt_click_allowed =
true;
287 bool opt_display =
true;
288 bool opt_pyramidal =
false;
289 TrackerType opt_tracker_type = TRACKER_SSD_INVERSE_COMPOSITIONAL;
290 WarpType opt_warp_type = WARP_AFFINE;
291 long opt_last_frame = 30;
297 if (! env_ipath.empty())
301 if (!getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display, opt_pyramidal,
302 opt_warp_type, opt_tracker_type, opt_last_frame)) {
307 if (opt_ipath.empty() && env_ipath.empty() ){
308 usage(argv[0], NULL, opt_warp_type, opt_tracker_type, opt_last_frame);
309 std::cerr << std::endl
310 <<
"ERROR:" << std::endl;
311 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
313 <<
" environment variable to specify the location of the " << std::endl
314 <<
" image path where test images are located." << std::endl
321 if (!opt_ipath.empty())
335 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
344 #if defined VISP_HAVE_X11
346 #elif defined VISP_HAVE_GDI
348 #elif defined VISP_HAVE_OPENCV
350 #elif defined VISP_HAVE_D3D9
352 #elif defined VISP_HAVE_GTK
357 #if (defined VISP_HAVE_DISPLAY)
358 display->init(I, 100, 100,
"Test tracking") ;
365 switch(opt_warp_type) {
371 #ifdef VISP_HAVE_MODULE_TT_MI
378 switch(opt_tracker_type) {
385 #ifdef VISP_HAVE_MODULE_TT_MI
401 bool delaunay =
false;
402 if (opt_display && opt_click_allowed)
405 std::vector<vpImagePoint> v_ip;
407 ip.
set_ij(166, 54); v_ip.push_back(ip);
408 ip.
set_ij(284, 55); v_ip.push_back(ip);
409 ip.
set_ij(259, 284); v_ip.push_back(ip);
410 ip.
set_ij(259, 284); v_ip.push_back(ip);
411 ip.
set_ij(149, 240); v_ip.push_back(ip);
412 ip.
set_ij(167, 58); v_ip.push_back(ip);
417 while (! reader.
end())
419 std::cout <<
"Process image number " << reader.
getFrameIndex() << std::endl;
429 std::cout <<
"re-init simulation" << std::endl;
430 if (opt_click_allowed)
435 if (opt_display && opt_click_allowed) {
441 std::vector<vpImagePoint> v_ip;
443 ip.
set_ij(146, 60); v_ip.push_back(ip);
444 ip.
set_ij(254, 74); v_ip.push_back(ip);
445 ip.
set_ij(228, 288); v_ip.push_back(ip);
446 ip.
set_ij(228, 288); v_ip.push_back(ip);
447 ip.
set_ij(126, 242); v_ip.push_back(ip);
448 ip.
set_ij(146, 60); v_ip.push_back(ip);
461 warp_->
warpZone(zoneRef_, p_, zoneWarped_);
468 if (opt_click_allowed) {
484 std::cout <<
"Catch an exception: " << e << std::endl;
493 std::cout <<
"visp_tt module or display not available." << std::endl;
long getFrameIndex() const
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)
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 display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, const unsigned int thickness=3)
void setIterationMax(const unsigned int &n)
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void open(vpImage< vpRGBa > &I)
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...
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 setFileName(const char *filename)
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)
void setLastFrameIndex(const long last_frame)
Implementation of column vector and the associated operations.
void track(const vpImage< unsigned char > &I)
vpTemplateTrackerZone getZoneRef() const
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 set_ij(const double ii, const double jj)
void setPyramidal(unsigned int nlevels=2, unsigned int level_to_stop=1)
vpTemplateTrackerWarp * getWarp() const
void setThresholdGradient(double threshold)
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, const unsigned int thickness=3)