49 #include <visp3/core/vpDebug.h>
50 #include <visp3/core/vpConfig.h>
57 #if defined(VISP_HAVE_MODULE_BLOB) && (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
59 #include <visp3/core/vpImage.h>
60 #include <visp3/io/vpImageIo.h>
61 #include <visp3/core/vpImagePoint.h>
62 #include <visp3/gui/vpDisplayX.h>
63 #include <visp3/gui/vpDisplayGTK.h>
64 #include <visp3/gui/vpDisplayGDI.h>
65 #include <visp3/gui/vpDisplayOpenCV.h>
66 #include <visp3/blob/vpDot2.h>
67 #include <visp3/io/vpParseArgv.h>
68 #include <visp3/core/vpIoTools.h>
71 #define GETOPTARGS "cdi:p:f:n:s:S:G:E:h"
73 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
74 unsigned first,
unsigned nimages,
unsigned step,
double sizePrecision,
75 double grayLevelPrecision,
double ellipsoidShapePrecision );
76 bool getOptions(
int argc,
const char **argv, std::string &ipath,
77 std::string &ppath,
unsigned &first,
unsigned &nimages,
78 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
79 double &ellipsoidShapePrecision,
bool &click_allowed,
bool &display);
98 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
99 unsigned first,
unsigned nimages,
unsigned step,
double sizePrecision,
100 double grayLevelPrecision,
double ellipsoidShapePrecision)
103 Test auto detection of dots using vpDot2.\n\
106 %s [-i <input image path>] [-p <personal image path>]\n\
107 [-f <first image>] [-n <number of images>] [-s <step>] \n\
108 [-S <size precision>] [-G <gray level precision>]\n\
109 [-E <ellipsoid shape precision>] [-c] [-d] [-h]\n", name);
113 -i <input image path> %s\n\
114 Set image input path.\n\
115 From this path read images \n\
116 \"ViSP-images/mire-2/image.%%04d.pgm\"\n\
117 Setting the VISP_INPUT_IMAGE_PATH environment\n\
118 variable produces the same behaviour than using\n\
121 -p <personal image path> %s\n\
122 Specify a personal sequence containing images \n\
124 By image sequence, we mean one file per image.\n\
125 The following image file formats PNM (PGM P5, PPM P6)\n\
126 are supported. The format is selected by analysing \n\
127 the filename extension.\n\
128 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
129 %%04d is for the image numbering.\n\
131 -f <first image> %u\n\
132 First image number of the sequence.\n\
134 -n <number of images> %u\n\
135 Number of images to load from the sequence.\n\
138 Step between two images.\n\
140 -S <size precision> %f\n\
141 Precision of the size of the dot. \n\
142 It is a double precision float witch value is in ]0,1].\n\
143 1 means full precision, the sizes (width, heigth, surface) \n\
144 of the dots must the same, whereas values close to 0 \n\
145 show a very bad precision.\n\
147 -G <gray level precision> %f\n\
148 Precision of the gray level of the dot. \n\
149 It is a double precision float witch value is in ]0,1].\n\
150 1 means full precision, the gray level must the same in \n\
151 the wall dot, whereas values close to 0 \n\
152 show a very bad precision.\n\
154 -E <ellipsoid shape precision> %f\n\
155 Precision of the ellipsoid shape of the dot. \n\
156 It is a double precision float witch value is in [0,1].\n\
157 1 means full precision, the shape should be a perfect ellipsoid,\n\
158 whereas values close to 0 show a very bad precision.\n\
159 0 means the shape of dots is not tested \n\
161 ipath.c_str(),ppath.c_str(), first, nimages, step, sizePrecision,
162 grayLevelPrecision, ellipsoidShapePrecision );
166 Disable the mouse click. Useful to automaze the \n\
167 execution of this program without humain intervention.\n\
170 Turn off the display.\n\
176 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
198 bool getOptions(
int argc,
const char **argv, std::string &ipath,
199 std::string &ppath,
unsigned &first,
unsigned &nimages,
200 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
201 double &ellipsoidShapePrecision,
bool &click_allowed,
bool &display)
208 case 'c': click_allowed =
false;
break;
209 case 'd': display =
false;
break;
210 case 'i': ipath = optarg_;
break;
211 case 'p': ppath = optarg_;
break;
212 case 'f': first = (unsigned) atoi(optarg_);
break;
213 case 'n': nimages = (unsigned) atoi(optarg_);
break;
214 case 's': step = (unsigned) atoi(optarg_);
break;
215 case 'S': sizePrecision = atof(optarg_);
break;
216 case 'G': grayLevelPrecision = atof(optarg_);
break;
217 case 'E': ellipsoidShapePrecision = atof(optarg_);
break;
218 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step,
219 sizePrecision,grayLevelPrecision,ellipsoidShapePrecision);
223 usage(argv[0], optarg_, ipath, ppath, first, nimages, step,
224 sizePrecision,grayLevelPrecision,ellipsoidShapePrecision);
229 if ((c == 1) || (c == -1)) {
231 usage(argv[0], NULL, ipath, ppath, first, nimages, step,
232 sizePrecision,grayLevelPrecision,ellipsoidShapePrecision);
233 std::cerr <<
"ERROR: " << std::endl;
234 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
243 main(
int argc,
const char ** argv)
246 std::string env_ipath;
247 std::string opt_ipath;
249 std::string opt_ppath;
251 std::string filename;
252 unsigned opt_first = 1;
253 unsigned opt_nimages = 10;
254 unsigned opt_step = 1;
255 double opt_sizePrecision = 0.65;
256 double opt_grayLevelPrecision = 0.85;
257 double opt_ellipsoidShapePrecision = 0.8;
258 bool opt_click_allowed =
true;
259 bool opt_display =
true;
265 if (! env_ipath.empty())
269 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
270 opt_step,opt_sizePrecision,opt_grayLevelPrecision,
271 opt_ellipsoidShapePrecision, opt_click_allowed, opt_display) ==
false) {
276 if (!opt_ipath.empty())
281 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
282 if (ipath != env_ipath) {
283 std::cout << std::endl
284 <<
"WARNING: " << std::endl;
285 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
286 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
287 <<
" we skip the environment variable." << std::endl;
292 if (opt_ipath.empty() && env_ipath.empty()){
293 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages,
294 opt_step,opt_sizePrecision,opt_grayLevelPrecision, opt_ellipsoidShapePrecision);
295 std::cerr << std::endl
296 <<
"ERROR:" << std::endl;
297 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
299 <<
" environment variable to specify the location of the " << std::endl
300 <<
" image path where test images are located." << std::endl << std::endl
301 <<
" Use -p <personal image path> option if you want to "<<std::endl
302 <<
" use personal images." << std::endl;
311 std::ostringstream s;
312 char cfilename[FILENAME_MAX];
313 unsigned iter = opt_first;
315 if (opt_ppath.empty()){
335 s.setf(std::ios::right, std::ios::adjustfield);
336 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
341 sprintf(cfilename,opt_ppath.c_str(), iter) ;
342 filename = cfilename;
351 vpCTRACE <<
"Load: " << filename << std::endl;
361 std::cerr << std::endl
362 <<
"ERROR:" << std::endl;
363 std::cerr <<
" Cannot read " << filename << std::endl;
364 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
365 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
366 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
373 #if defined VISP_HAVE_GTK
375 #elif defined VISP_HAVE_X11
377 #elif defined VISP_HAVE_GDI
379 #elif defined VISP_HAVE_OPENCV
385 display.
init(I, 100, 100,
"Display...") ;
399 if (opt_click_allowed & opt_display) {
402 std::cout <<
"Please click on a dot to initialize detection"
414 printf(
"Dot characteristics: \n");
415 printf(
" width : %lf\n", d.
getWidth());
417 printf(
" area: %lf\n", d.
getArea());
437 while (iter < opt_first + opt_nimages*opt_step)
441 if (opt_ppath.empty()){
444 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
448 sprintf(cfilename, opt_ppath.c_str(), iter) ;
449 filename = cfilename;
459 std::cout <<
"Search dots in image" << filename << std::endl;
460 std::list<vpDot2> list_d;
463 if( list_d.empty() ) {
464 std::cout <<
"Dot auto detection did not work." << std::endl;
468 std::cout << std::endl << list_d.size() <<
" dots are detected" << std::endl;
473 for (std::list<vpDot2>::const_iterator it = list_d.begin(); it != list_d.end(); ++ it)
477 std::cout <<
"Dot " << i++ <<
" : " << cog.
get_u()
478 <<
" " << cog.
get_v() << std::endl;
487 if (opt_display && opt_click_allowed) {
488 std::cout <<
"\nA click to continue..." << std::endl;
495 if (opt_display && opt_click_allowed) {
496 std::cout <<
"\nA click to exit..." << std::endl;
504 std::cout <<
"Catch an exception: " << e << std::endl;
513 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display functionalities are required..." << std::endl;
void setGrayLevelMax(const unsigned int &max)
void searchDotsInArea(const vpImage< unsigned char > &I, int area_u, int area_v, unsigned int area_w, unsigned int area_h, std::list< vpDot2 > &niceDots)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
unsigned int getWidth() const
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="")
double getEllipsoidShapePrecision() const
static const vpColor green
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
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)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
unsigned int getGrayLevelMin() const
void setArea(const double &area)
void setEllipsoidShapePrecision(const double &ellipsoidShapePrecision)
void setGrayLevelMin(const unsigned int &min)
void setWidth(const double &width)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
void setSizePrecision(const double &sizePrecision)
static void read(vpImage< unsigned char > &I, const std::string &filename)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
void setHeight(const double &height)
unsigned int getHeight() const
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)
static const vpColor blue