44 #include <visp3/core/vpDebug.h>
45 #include <visp3/core/vpConfig.h>
52 #if defined(VISP_HAVE_MODULE_BLOB) && (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
54 #include <visp3/core/vpImage.h>
55 #include <visp3/io/vpImageIo.h>
56 #include <visp3/core/vpImagePoint.h>
57 #include <visp3/gui/vpDisplayX.h>
58 #include <visp3/gui/vpDisplayGTK.h>
59 #include <visp3/gui/vpDisplayGDI.h>
60 #include <visp3/gui/vpDisplayOpenCV.h>
61 #include <visp3/blob/vpDot2.h>
62 #include <visp3/io/vpParseArgv.h>
63 #include <visp3/core/vpIoTools.h>
66 #define GETOPTARGS "cdf:i:n:p:s:h"
70 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
71 unsigned first,
unsigned nimages,
unsigned step);
72 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
73 unsigned &nimages,
unsigned &step,
bool &click_allowed,
bool &display);
93 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
94 unsigned first,
unsigned nimages,
unsigned step)
97 Test dot tracking using vpDot2 class.\n\
100 %s [-i <test image path>] [-p <personal image path>]\n\
101 [-f <first image>] [-n <number of images>] [-s <step>]\n\
102 [-c] [-d] [-h]\n", name);
106 -i <input image path> %s\n\
107 Set image input path.\n\
108 From this path read images \n\
109 \"ViSP-images/mire-2/image.%%04d.pgm\". These \n\
110 images come from ViSP-images-x.y.z.tar.gz available \n\
111 on the ViSP website.\n\
112 Setting the VISP_INPUT_IMAGE_PATH environment\n\
113 variable produces the same behaviour than using\n\
116 -p <personal image path> %s\n\
117 Specify a personal sequence containing images \n\
119 By image sequence, we mean one file per image.\n\
120 The following image file formats PNM (PGM P5, PPM P6)\n\
121 are supported. The format is selected by analysing \n\
122 the filename extension.\n\
123 Example : \"C:/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
124 %%04d is for the image numbering.\n\
126 -f <first image> %u\n\
127 First image number of the sequence.\n\
129 -n <number of images> %u\n\
130 Number of images to load from the sequence.\n\
133 Step between two images.\n\
136 Disable the mouse click. Useful to automaze the \n\
137 execution of this program without humain intervention.\n\
140 Turn off the display.\n\
144 ipath.c_str(), ppath.c_str(), first, nimages, step);
147 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
166 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
167 unsigned &nimages,
unsigned &step,
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;
202 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;
221 if (! env_ipath.empty())
225 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
226 opt_step, opt_click_allowed, opt_display) ==
false) {
231 if (!opt_ipath.empty())
236 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
237 if (ipath != env_ipath) {
238 std::cout << std::endl
239 <<
"WARNING: " << std::endl;
240 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
241 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
242 <<
" we skip the environment variable." << std::endl;
247 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
248 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
249 std::cerr << std::endl
250 <<
"ERROR:" << std::endl;
251 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
253 <<
" environment variable to specify the location of the " << std::endl
254 <<
" image path where test images are located." << std::endl
255 <<
" Use -p <personal image path> option if you want to "<<std::endl
256 <<
" use personal images." << std::endl
267 unsigned iter = opt_first;
268 std::ostringstream s;
269 char cfilename[FILENAME_MAX];
271 if (opt_ppath.empty()){
291 s.setf(std::ios::right, std::ios::adjustfield);
292 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
297 sprintf(cfilename,opt_ppath.c_str(), iter) ;
298 filename = cfilename;
308 vpCTRACE <<
"Load: " << filename << std::endl;
318 std::cerr << std::endl
319 <<
"ERROR:" << std::endl;
320 std::cerr <<
" Cannot read " << filename << std::endl;
321 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
322 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
328 #if defined VISP_HAVE_X11
330 #elif defined VISP_HAVE_GTK
332 #elif defined VISP_HAVE_GDI
334 #elif defined VISP_HAVE_OPENCV
340 display.
init(I, 100, 100,
"Display...") ;
383 if (opt_display && opt_click_allowed) {
384 std::cout <<
"Click on a dot to track it."<< std::endl;
394 std::cout <<
"COG: " << std::endl;
396 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v()
399 std::cout <<
"Size:" << std::endl;
401 std::cout <<
"Area: " << d.
getArea() << std::endl;
402 std::cout <<
"Moments:" << std::endl;
403 std::cout <<
" m00: " << d.
m00 << std::endl;
404 std::cout <<
" m10: " << d.
m10 << std::endl;
405 std::cout <<
" m01: " << d.
m01 << std::endl;
406 std::cout <<
" m11: " << d.
m11 << std::endl;
407 std::cout <<
" m02: " << d.
m02 << std::endl;
408 std::cout <<
" m20: " << d.
m20 << std::endl;
409 std::cout <<
"Centered moments:" << std::endl;
410 std::cout <<
" mu11: " << d.
mu11 << std::endl;
411 std::cout <<
" mu02: " << d.
mu02 << std::endl;
412 std::cout <<
" mu20: " << d.
mu20 << std::endl;
413 std::cout <<
"Settings:" << std::endl;
420 while (iter < opt_first + opt_nimages*opt_step) {
422 if (opt_ppath.empty()){
424 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
428 sprintf(cfilename, opt_ppath.c_str(), iter) ;
429 filename = cfilename;
432 std::cout <<
"read : " << filename << std::endl;
446 std::cout <<
"Tracking on image: " << filename << std::endl;
453 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v()
456 std::cout <<
"Size:" << std::endl;
458 std::cout <<
"Area: " << d.
getArea() << std::endl;
459 std::cout <<
"Moments:" << std::endl;
460 std::cout <<
" m00: " << d.
m00 << std::endl;
461 std::cout <<
" m10: " << d.
m10 << std::endl;
462 std::cout <<
" m01: " << d.
m01 << std::endl;
463 std::cout <<
" m11: " << d.
m11 << std::endl;
464 std::cout <<
" m02: " << d.
m02 << std::endl;
465 std::cout <<
" m20: " << d.
m20 << std::endl;
466 std::cout <<
"Centered moments:" << std::endl;
467 std::cout <<
" mu11: " << d.
mu11 << std::endl;
468 std::cout <<
" mu02: " << d.
mu02 << std::endl;
469 std::cout <<
" mu20: " << d.
mu20 << std::endl;
470 std::cout <<
"Settings:" << std::endl;
479 std::list<vpImagePoint> edges;
481 std::list<vpImagePoint>::const_iterator it;
482 for(it = edges.begin(); it != edges.end(); ++it) {
497 if (opt_display && opt_click_allowed) {
498 std::cout <<
"\nA click to exit..." << std::endl;
505 std::cout <<
"Catch an exception: " << e << std::endl;
514 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display functionalities are required..." << std::endl;
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
double getGrayLevelPrecision() const
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
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
VISP_EXPORT double measureTimeMs()
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)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void set_v(const double v)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
unsigned int getGrayLevelMin() const
void setComputeMoments(const bool activate)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void read(vpImage< unsigned char > &I, const std::string &filename)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getGrayLevelMax() const
void setGraphics(const bool activate)
void getEdges(std::list< vpImagePoint > &edges_list) const
static const vpColor blue