48 #include <visp/vpDebug.h>
49 #include <visp/vpConfig.h>
56 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
58 #include <visp/vpImage.h>
59 #include <visp/vpImageIo.h>
60 #include <visp/vpImagePoint.h>
61 #include <visp/vpDisplayX.h>
62 #include <visp/vpDisplayGTK.h>
63 #include <visp/vpDisplayGDI.h>
64 #include <visp/vpDot2.h>
65 #include <visp/vpParseArgv.h>
66 #include <visp/vpIoTools.h>
69 #define GETOPTARGS "cdf:i:n:p:s:h"
73 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
74 unsigned first,
unsigned nimages,
unsigned step);
75 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
76 unsigned &nimages,
unsigned &step,
bool &click_allowed,
bool &display);
96 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
97 unsigned first,
unsigned nimages,
unsigned step)
100 Test dot tracking using vpDot2 class.\n\
103 %s [-i <test image path>] [-p <personal image path>]\n\
104 [-f <first image>] [-n <number of images>] [-s <step>]\n\
105 [-c] [-d] [-h]\n", name);
109 -i <input image path> %s\n\
110 Set image input path.\n\
111 From this path read images \n\
112 \"ViSP-images/mire-2/image.%%04d.pgm\". These \n\
113 images come from ViSP-images-x.y.z.tar.gz available \n\
114 on the ViSP website.\n\
115 Setting the VISP_INPUT_IMAGE_PATH environment\n\
116 variable produces the same behaviour than using\n\
119 -p <personal image path> %s\n\
120 Specify a personal sequence containing images \n\
122 By image sequence, we mean one file per image.\n\
123 The following image file formats PNM (PGM P5, PPM P6)\n\
124 are supported. The format is selected by analysing \n\
125 the filename extension.\n\
126 Example : \"C:/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
127 %%04d is for the image numbering.\n\
129 -f <first image> %u\n\
130 First image number of the sequence.\n\
132 -n <number of images> %u\n\
133 Number of images to load from the sequence.\n\
136 Step between two images.\n\
139 Disable the mouse click. Useful to automaze the \n\
140 execution of this program without humain intervention.\n\
143 Turn off the display.\n\
147 ipath.c_str(), ppath.c_str(), first, nimages, step);
150 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
169 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
170 unsigned &nimages,
unsigned &step,
bool &click_allowed,
bool &display)
177 case 'c': click_allowed =
false;
break;
178 case 'd': display =
false;
break;
179 case 'i': ipath = optarg_;
break;
180 case 'p': ppath = optarg_;
break;
181 case 'f': first = (unsigned) atoi(optarg_);
break;
182 case 'n': nimages = (unsigned) atoi(optarg_);
break;
183 case 's': step = (unsigned) atoi(optarg_);
break;
184 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step);
188 usage(argv[0], optarg_, ipath, ppath, first, nimages, step);
193 if ((c == 1) || (c == -1)) {
195 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
196 std::cerr <<
"ERROR: " << std::endl;
197 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
205 main(
int argc,
const char ** argv)
208 std::string env_ipath;
209 std::string opt_ipath;
211 std::string opt_ppath;
213 std::string filename;
214 unsigned opt_first = 1;
215 unsigned opt_nimages = 500;
216 unsigned opt_step = 1;
217 bool opt_click_allowed =
true;
218 bool opt_display =
true;
221 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
226 if (! env_ipath.empty())
231 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
232 opt_step, opt_click_allowed, opt_display) ==
false) {
237 if (!opt_ipath.empty())
242 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
243 if (ipath != env_ipath) {
244 std::cout << std::endl
245 <<
"WARNING: " << std::endl;
246 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
247 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
248 <<
" we skip the environment variable." << std::endl;
253 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
254 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
255 std::cerr << std::endl
256 <<
"ERROR:" << std::endl;
257 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
259 <<
" environment variable to specify the location of the " << std::endl
260 <<
" image path where test images are located." << std::endl
261 <<
" Use -p <personal image path> option if you want to "<<std::endl
262 <<
" use personal images." << std::endl
273 unsigned iter = opt_first;
274 std::ostringstream s;
275 char cfilename[FILENAME_MAX];
277 if (opt_ppath.empty()){
297 s.setf(std::ios::right, std::ios::adjustfield);
298 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
299 filename = dirname + s.str();
303 sprintf(cfilename,opt_ppath.c_str(), iter) ;
304 filename = cfilename;
314 vpCTRACE <<
"Load: " << filename << std::endl;
324 std::cerr << std::endl
325 <<
"ERROR:" << std::endl;
326 std::cerr <<
" Cannot read " << filename << std::endl;
327 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
328 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
334 #if defined VISP_HAVE_X11
336 #elif defined VISP_HAVE_GTK
338 #elif defined VISP_HAVE_GDI
344 display.
init(I, 100, 100,
"Display...") ;
387 if (opt_display && opt_click_allowed) {
388 std::cout <<
"Click on a dot to track it."<< std::endl;
398 std::cout <<
"COG: " << std::endl;
400 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v()
403 std::cout <<
"Size:" << std::endl;
405 std::cout <<
"Area: " << d.
getArea() << std::endl;
406 std::cout <<
"Moments:" << std::endl;
407 std::cout <<
" m00: " << d.
m00 << std::endl;
408 std::cout <<
" m10: " << d.
m10 << std::endl;
409 std::cout <<
" m01: " << d.
m01 << std::endl;
410 std::cout <<
" m11: " << d.
m11 << std::endl;
411 std::cout <<
" m02: " << d.
m02 << std::endl;
412 std::cout <<
" m20: " << d.
m20 << std::endl;
413 std::cout <<
"Centered moments:" << std::endl;
414 std::cout <<
" mu11: " << d.
mu11 << std::endl;
415 std::cout <<
" mu02: " << d.
mu02 << std::endl;
416 std::cout <<
" mu20: " << d.
mu20 << std::endl;
417 std::cout <<
"Settings:" << std::endl;
424 while (iter < opt_first + opt_nimages*opt_step) {
426 if (opt_ppath.empty()){
428 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
429 filename = dirname + s.str();
432 sprintf(cfilename, opt_ppath.c_str(), iter) ;
433 filename = cfilename;
436 std::cout <<
"read : " << filename << std::endl;
450 std::cout <<
"Tracking on image: " << filename << std::endl;
457 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v()
460 std::cout <<
"Size:" << std::endl;
462 std::cout <<
"Area: " << d.
getArea() << std::endl;
463 std::cout <<
"Moments:" << std::endl;
464 std::cout <<
" m00: " << d.
m00 << std::endl;
465 std::cout <<
" m10: " << d.
m10 << std::endl;
466 std::cout <<
" m01: " << d.
m01 << std::endl;
467 std::cout <<
" m11: " << d.
m11 << std::endl;
468 std::cout <<
" m02: " << d.
m02 << std::endl;
469 std::cout <<
" m20: " << d.
m20 << std::endl;
470 std::cout <<
"Centered moments:" << std::endl;
471 std::cout <<
" mu11: " << d.
mu11 << std::endl;
472 std::cout <<
" mu02: " << d.
mu02 << std::endl;
473 std::cout <<
" mu20: " << d.
mu20 << std::endl;
474 std::cout <<
"Settings:" << std::endl;
483 std::list<vpImagePoint> edges;
485 std::list<vpImagePoint>::const_iterator it;
486 for(it = edges.begin(); it != edges.end(); ++it) {
501 if (opt_display && opt_click_allowed) {
502 std::cout <<
"\nA click to exit..." << std::endl;
509 std::cout <<
"Catch an exception: " << e << std::endl;
517 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
Display for windows using GDI (available on any windows 32 platform).
double getGrayLevelPrecision() const
Define the X11 console to display images.
error that can be emited by ViSP classes.
static double measureTimeMs()
static const vpColor green
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
void track(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
double getSizePrecision() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
vpImagePoint getCog() const
void setGrayLevelPrecision(const double &grayLevelPrecision)
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)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
unsigned int getGrayLevelMin() const
void setComputeMoments(const bool activate)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
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)
unsigned int getGrayLevelMax() const
void setGraphics(const bool activate)
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0
void getEdges(std::list< vpImagePoint > &edges_list) const
static const vpColor blue