56 #include <visp/vpDebug.h>
57 #include <visp/vpConfig.h>
64 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
66 #include <visp/vpImage.h>
67 #include <visp/vpImageIo.h>
68 #include <visp/vpImagePoint.h>
69 #include <visp/vpDisplayX.h>
70 #include <visp/vpDisplayGTK.h>
71 #include <visp/vpDisplayGDI.h>
72 #include <visp/vpDot.h>
73 #include <visp/vpParseArgv.h>
74 #include <visp/vpIoTools.h>
77 #define GETOPTARGS "cdf:i:n:p:s:h"
92 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
93 unsigned first,
unsigned nimages,
unsigned step)
99 %s [-i <test image path>] [-p <personal image path>]\n\
100 [-f <first image>] [-n <number of images>] [-s <step>]\n\
101 [-c] [-d] [-h]\n", name);
105 -i <input image path> %s\n\
106 Set image input path.\n\
107 From this path read images \n\
108 \"ViSP-images/mire-2/image.%%04d.pgm\". These \n\
109 images come from ViSP-images-x.y.z.tar.gz available \n\
110 on the ViSP website.\n\
111 Setting the VISP_INPUT_IMAGE_PATH environment\n\
112 variable produces the same behaviour than using\n\
115 -p <personal image path> %s\n\
116 Specify a personal sequence containing images \n\
118 By image sequence, we mean one file per image.\n\
119 The following image file formats PNM (PGM P5, PPM P6)\n\
120 are supported. The format is selected by analysing \n\
121 the filename extension.\n\
122 Example : \"C:/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
123 %%04d is for the image numbering.\n\
125 -f <first image> %u\n\
126 First image number of the sequence.\n\
128 -n <number of images> %u\n\
129 Number of images to load from the sequence.\n\
132 Step between two images.\n\
135 Disable the mouse click. Useful to automaze the \n\
136 execution of this program without humain intervention.\n\
139 Turn off the display.\n\
143 ipath.c_str(), ppath.c_str(), first, nimages, step);
146 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
165 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
166 unsigned &first,
unsigned &nimages,
unsigned &step,
167 bool &click_allowed,
bool &display)
174 case 'c': click_allowed =
false;
break;
175 case 'd': display =
false;
break;
176 case 'i': ipath = optarg;
break;
177 case 'p': ppath = optarg;
break;
178 case 'f': first = (unsigned) atoi(optarg);
break;
179 case 'n': nimages = (unsigned) atoi(optarg);
break;
180 case 's': step = (unsigned) atoi(optarg);
break;
181 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step);
185 usage(argv[0], optarg, ipath, ppath, first, nimages, step);
190 if ((c == 1) || (c == -1)) {
192 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
193 std::cerr <<
"ERROR: " << std::endl;
194 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
203 main(
int argc,
const char ** argv)
205 std::string env_ipath;
206 std::string opt_ipath;
208 std::string opt_ppath;
210 std::string filename;
211 unsigned opt_first = 1;
212 unsigned opt_nimages = 500;
213 unsigned opt_step = 1;
214 bool opt_click_allowed =
true;
215 bool opt_display =
true;
218 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
223 if (! env_ipath.empty())
227 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
228 opt_step, opt_click_allowed, opt_display) ==
false) {
233 if (!opt_ipath.empty())
238 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
239 if (ipath != env_ipath) {
240 std::cout << std::endl
241 <<
"WARNING: " << std::endl;
242 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
243 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
244 <<
" we skip the environment variable." << std::endl;
249 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
250 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
251 std::cerr << std::endl
252 <<
"ERROR:" << std::endl;
253 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
255 <<
" environment variable to specify the location of the " << std::endl
256 <<
" image path where test images are located." << std::endl
257 <<
" Use -p <personal image path> option if you want to "<<std::endl
258 <<
" use personal images." << std::endl
269 unsigned iter = opt_first;
270 std::ostringstream s;
271 char cfilename[FILENAME_MAX];
273 if (opt_ppath.empty()){
293 s.setf(std::ios::right, std::ios::adjustfield);
294 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
295 filename = dirname + s.str();
299 sprintf(cfilename,opt_ppath.c_str(), iter) ;
300 filename = cfilename;
310 vpCTRACE <<
"Load: " << filename << std::endl;
320 std::cerr << std::endl
321 <<
"ERROR:" << std::endl;
322 std::cerr <<
" Cannot read " << filename << std::endl;
323 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
324 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
330 #if defined VISP_HAVE_X11
332 #elif defined VISP_HAVE_GTK
334 #elif defined VISP_HAVE_GDI
341 display.
init(I, 100, 100,
"Display...") ;
374 if (opt_display && opt_click_allowed) {
378 std::cout <<
"Click on a white dot you want to track..." << std::endl;
399 while (iter < opt_first + opt_nimages*opt_step) {
401 if (opt_ppath.empty()){
403 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
404 filename = dirname + s.str();
407 sprintf(cfilename, opt_ppath.c_str(), iter) ;
408 filename = cfilename;
411 std::cout <<
"read : " << filename << std::endl;
418 std::cout <<
"Tracking on image: " << filename << std::endl;
427 std::cout << cog.
get_u() <<
" " << cog.
get_v()
430 std::cout <<
"Size:" << std::endl;
432 std::cout <<
"Moments:" << std::endl;
433 std::cout <<
" m00: " << d.
m00 << std::endl;
434 std::cout <<
" m10: " << d.
m10 << std::endl;
435 std::cout <<
" m01: " << d.
m01 << std::endl;
436 std::cout <<
" m11: " << d.
m11 << std::endl;
437 std::cout <<
" m02: " << d.
m02 << std::endl;
438 std::cout <<
" m20: " << d.
m20 << std::endl;
439 std::cout <<
"Centered moments:" << std::endl;
440 std::cout <<
" mu11: " << d.
mu11 << std::endl;
441 std::cout <<
" mu02: " << d.
mu02 << std::endl;
442 std::cout <<
" mu20: " << d.
mu20 << std::endl;
445 std::list<vpImagePoint> edges = d.
getEdges();
446 std::list<vpImagePoint>::const_iterator it;
447 for(it = edges.begin(); it != edges.end(); ++it) {
463 std::cerr <<
"Error during the tracking..." << std::endl;
464 std::cerr <<
"The progam was stopped." << std::endl;
468 if (opt_display && opt_click_allowed) {
469 std::cout <<
"\nA click to exit..." << std::endl;
478 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
unsigned int getHeight() const
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
void track(const vpImage< unsigned char > &I)
static double measureTimeMs()
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
vpImagePoint getCog() const
void set_u(const double u)
static void display(const vpImage< unsigned char > &I)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
void set_v(const double v)
unsigned int getWidth() const
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void setGraphics(const bool activate)
std::list< vpImagePoint > getEdges()
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
void setComputeMoments(const bool activate)
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 ...
static void read(vpImage< unsigned char > &I, const char *filename)
void initTracking(const vpImage< unsigned char > &I)
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0
void setConnexity(vpConnexityType connexityType)
static const vpColor blue