49 #include <visp/vpConfig.h>
50 #include <visp/vpDebug.h>
51 #include <visp/vpDisplayD3D.h>
52 #include <visp/vpDisplayGTK.h>
53 #include <visp/vpDisplayGDI.h>
54 #include <visp/vpDisplayOpenCV.h>
55 #include <visp/vpDisplayX.h>
56 #include <visp/vpHomogeneousMatrix.h>
57 #include <visp/vpImageIo.h>
58 #include <visp/vpIoTools.h>
59 #include <visp/vpMath.h>
60 #include <visp/vpVideoReader.h>
61 #include <visp/vpParseArgv.h>
63 #include <visp/vpTemplateTrackerSSD.h>
64 #include <visp/vpTemplateTrackerSSDForwardAdditional.h>
65 #include <visp/vpTemplateTrackerSSDForwardCompositional.h>
66 #include <visp/vpTemplateTrackerSSDInverseCompositional.h>
67 #include <visp/vpTemplateTrackerSSDESM.h>
68 #include <visp/vpTemplateTrackerZNCCForwardAdditional.h>
69 #include <visp/vpTemplateTrackerZNCCInverseCompositional.h>
71 #include <visp/vpTemplateTrackerWarpAffine.h>
72 #include <visp/vpTemplateTrackerWarpHomography.h>
73 #include <visp/vpTemplateTrackerWarpHomographySL3.h>
74 #include <visp/vpTemplateTrackerWarpSRT.h>
75 #include <visp/vpTemplateTrackerWarpTranslation.h>
77 #if defined (VISP_HAVE_DISPLAY)
80 #define GETOPTARGS "cdhi:l:pt:w:"
82 #ifndef DOXYGEN_SHOULD_SKIP_THIS
93 TRACKER_SSD_FORWARD_ADDITIONAL,
94 TRACKER_SSD_FORWARD_COMPOSITIONAL,
95 TRACKER_SSD_INVERSE_COMPOSITIONAL,
96 TRACKER_ZNCC_FORWARD_ADDITIONEL,
97 TRACKER_ZNCC_INVERSE_COMPOSITIONAL
102 void usage(
const char *name,
const char *badparam,
const WarpType &warp_type,
103 TrackerType &tracker_type,
const long &last_frame);
104 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
105 bool &pyramidal, WarpType &warp_type, TrackerType &tracker_type,
long &last_frame);
107 void usage(
const char *name,
const char *badparam,
const WarpType &warp_type,
108 TrackerType &tracker_type,
const long &last_frame)
111 Example of template tracking.\n\
114 %s [-i <test image path>] [-c] [-d] [-p] \n\
115 [-w <warp type>] [-t <tracker type>] \n\
116 [-l <last frame number>] [-h]\n", name );
120 -i <input image path> \n\
121 Set image input path.\n\
122 From this path read images \n\
123 \"ViSP-images/cube/image%%04d.pgm\". These \n\
124 images come from ViSP-images-x.y.z.tar.gz available \n\
125 on the ViSP website.\n\
126 Setting the VISP_INPUT_IMAGE_PATH environment\n\
127 variable produces the same behaviour than using\n\
130 -l <last frame number> %ld\n\
131 Last frame number to consider.\n\
134 Turn off the display.\n\
137 Disable the mouse click. Useful to automaze the \n\
138 execution of this program without humain intervention.\n\
140 -w <warp type=[0,1,2,3,4]> %d\n\
141 Set the model used to warp the template. \n\
142 Authorized values are:\n\
145 %d : Homography in SL3\n\
146 %d : SRT (scale, rotation, translation)\n\
149 -t <tracker type=[0,1,2,3,4,5]> %d\n\
150 Set the tracker used to track the template. \n\
151 Authorized values are:\n\
153 %d : SSD forward additional\n\
154 %d : SSD forward compositional\n\
155 %d : SSD inverse compositional\n\
156 %d : ZNCC forward additional\n\
157 %d : ZNCC inverse compositional\n\
160 Enable pyramidal tracking.\n\
163 Print the help.\n\n",
164 last_frame, (
int)warp_type,
165 (
int)WARP_AFFINE, (
int)WARP_HOMOGRAPHY, (
int)WARP_HOMOGRAPHY_SL3, (
int)WARP_SRT, (
int)WARP_TRANSLATION,
167 (
int)TRACKER_SSD_ESM, (
int)TRACKER_SSD_FORWARD_ADDITIONAL, (
int)TRACKER_SSD_FORWARD_COMPOSITIONAL,
168 (
int)TRACKER_SSD_INVERSE_COMPOSITIONAL, (
int)TRACKER_ZNCC_FORWARD_ADDITIONEL,
169 (
int)TRACKER_ZNCC_INVERSE_COMPOSITIONAL);
171 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
175 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
176 bool &pyramidal, WarpType &warp_type, TrackerType &tracker_type,
long &last_frame)
183 case 'c': click_allowed =
false;
break;
184 case 'd': display =
false;
break;
185 case 'h': usage(argv[0], NULL, warp_type, tracker_type, last_frame);
return false;
break;
186 case 'i': ipath = optarg_;
break;
187 case 'l': last_frame = (long)atoi(optarg_);
break;
188 case 'p': pyramidal =
true;
break;
189 case 't': tracker_type = (TrackerType)atoi(optarg_);
break;
190 case 'w': warp_type = (WarpType)atoi(optarg_);
break;
193 usage(argv[0], optarg_, warp_type, tracker_type, last_frame);
198 if (warp_type > WARP_TRANSLATION) {
199 usage(argv[0], NULL, warp_type, tracker_type, last_frame);
200 std::cerr <<
"ERROR: " << std::endl;
201 std::cerr <<
" Bad argument -w <warp type> with \"warp type\"=" << (int)warp_type << std::endl << std::endl;
204 if (tracker_type > TRACKER_ZNCC_INVERSE_COMPOSITIONAL) {
205 usage(argv[0], NULL, warp_type, tracker_type, last_frame);
206 std::cerr <<
"ERROR: " << std::endl;
207 std::cerr <<
" Bad argument -t <tracker type> with \"tracker type\"=" << (int)tracker_type << std::endl << std::endl;
210 if ((c == 1) || (c == -1)) {
212 usage(argv[0], NULL, warp_type, tracker_type, last_frame);
213 std::cerr <<
"ERROR: " << std::endl;
214 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
222 main(
int argc,
const char ** argv)
225 std::string env_ipath;
226 std::string opt_ipath;
228 bool opt_click_allowed =
true;
229 bool opt_display =
true;
230 bool opt_pyramidal =
false;
231 TrackerType opt_tracker_type = TRACKER_SSD_INVERSE_COMPOSITIONAL;
232 WarpType opt_warp_type = WARP_AFFINE;
233 long opt_last_frame = 30;
236 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
241 if (! env_ipath.empty())
245 if (!getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display, opt_pyramidal,
246 opt_warp_type, opt_tracker_type, opt_last_frame)) {
251 if (opt_ipath.empty() && env_ipath.empty() ){
252 usage(argv[0], NULL, opt_warp_type, opt_tracker_type, opt_last_frame);
253 std::cerr << std::endl
254 <<
"ERROR:" << std::endl;
255 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
257 <<
" environment variable to specify the location of the " << std::endl
258 <<
" image path where test images are located." << std::endl
265 if (!opt_ipath.empty())
266 ipath = opt_ipath +
vpIoTools::path(
"/ViSP-images/mire-2/image.%04d.pgm");
268 ipath = env_ipath +
vpIoTools::path(
"/ViSP-images/mire-2/image.%04d.pgm");
279 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
288 #if defined VISP_HAVE_X11
290 #elif defined VISP_HAVE_GDI
292 #elif defined VISP_HAVE_OPENCV
294 #elif defined VISP_HAVE_D3D9
296 #elif defined VISP_HAVE_GTK
301 #if (defined VISP_HAVE_DISPLAY)
302 display->
init(I, 100, 100,
"Test tracking") ;
309 switch(opt_warp_type) {
318 switch(opt_tracker_type) {
334 bool delaunay =
false;
335 if (opt_display && opt_click_allowed)
338 std::vector<vpImagePoint> v_ip;
340 ip.
set_ij(166, 54); v_ip.push_back(ip);
341 ip.
set_ij(284, 55); v_ip.push_back(ip);
342 ip.
set_ij(259, 284); v_ip.push_back(ip);
343 ip.
set_ij(259, 284); v_ip.push_back(ip);
344 ip.
set_ij(149, 240); v_ip.push_back(ip);
345 ip.
set_ij(167, 58); v_ip.push_back(ip);
350 while (! reader.
end())
352 std::cout <<
"Process image number " << reader.
getFrameIndex() << std::endl;
362 std::cout <<
"re-init simulation" << std::endl;
363 if (opt_click_allowed)
368 if (opt_display && opt_click_allowed) {
374 std::vector<vpImagePoint> v_ip;
376 ip.
set_ij(146, 60); v_ip.push_back(ip);
377 ip.
set_ij(254, 74); v_ip.push_back(ip);
378 ip.
set_ij(228, 288); v_ip.push_back(ip);
379 ip.
set_ij(228, 288); v_ip.push_back(ip);
380 ip.
set_ij(126, 242); v_ip.push_back(ip);
381 ip.
set_ij(146, 60); v_ip.push_back(ip);
394 warp_->
warpZone(zoneRef_, p_, zoneWarped_);
401 if (opt_click_allowed) {
417 std::cout <<
"Catch an exception: " << e << std::endl;
426 std::cout <<
"No display is available." << std::endl;
long getFrameIndex() const
virtual void init(vpImage< unsigned char > &I, int x=-1, int y=-1, const char *title=NULL)=0
Class that defines generic functionnalities for display.
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
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.
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
void initClick(const vpImage< unsigned char > &I, bool delaunay=false)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
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)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
void track(const vpImage< unsigned char > &I)
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
vpTemplateTrackerZone getZoneRef() const
void setFirstFrameIndex(const long first_frame)
virtual bool getClick(bool blocking=true)=0
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 setSampling(int _mod_i, int _mod_j)
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, const unsigned int thickness=3)