53 #include <visp/vpDebug.h>
54 #include <visp/vpConfig.h>
61 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
63 #include <visp/vpImage.h>
64 #include <visp/vpImageIo.h>
65 #include <visp/vpImagePoint.h>
66 #include <visp/vpDisplayX.h>
67 #include <visp/vpDisplayGTK.h>
68 #include <visp/vpDisplayGDI.h>
69 #include <visp/vpList.h>
70 #include <visp/vpDot2.h>
71 #include <visp/vpParseArgv.h>
72 #include <visp/vpIoTools.h>
75 #define GETOPTARGS "cdi:p:f:n:s:S:G:E:h"
77 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
78 unsigned first,
unsigned nimages,
unsigned step,
double sizePrecision,
79 double grayLevelPrecision,
double ellipsoidShapePrecision );
80 bool getOptions(
int argc,
const char **argv, std::string &ipath,
81 std::string &ppath,
unsigned &first,
unsigned &nimages,
82 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
83 double &ellipsoidShapePrecision,
bool &click_allowed,
bool &display);
102 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
103 unsigned first,
unsigned nimages,
unsigned step,
double sizePrecision,
104 double grayLevelPrecision,
double ellipsoidShapePrecision)
107 Test auto detection of dots using vpDot2.\n\
110 %s [-i <input image path>] [-p <personal image path>]\n\
111 [-f <first image>] [-n <number of images>] [-s <step>] \n\
112 [-S <size precision>] [-G <gray level precision>]\n\
113 [-E <ellipsoid shape precision>] [-c] [-d] [-h]\n", name);
117 -i <input image path> %s\n\
118 Set image input path.\n\
119 From this path read images \n\
120 \"ViSP-images/mire-2/image.%%04d.pgm\"\n\
121 Setting the VISP_INPUT_IMAGE_PATH environment\n\
122 variable produces the same behaviour than using\n\
125 -p <personal image path> %s\n\
126 Specify a personal sequence containing images \n\
128 By image sequence, we mean one file per image.\n\
129 The following image file formats PNM (PGM P5, PPM P6)\n\
130 are supported. The format is selected by analysing \n\
131 the filename extension.\n\
132 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
133 %%04d is for the image numbering.\n\
135 -f <first image> %u\n\
136 First image number of the sequence.\n\
138 -n <number of images> %u\n\
139 Number of images to load from the sequence.\n\
142 Step between two images.\n\
144 -S <size precision> %f\n\
145 Precision of the size of the dot. \n\
146 It is a double precision float witch value is in ]0,1].\n\
147 1 means full precision, the sizes (width, heigth, surface) \n\
148 of the dots must the same, whereas values close to 0 \n\
149 show a very bad precision.\n\
151 -G <gray level precision> %f\n\
152 Precision of the gray level of the dot. \n\
153 It is a double precision float witch value is in ]0,1].\n\
154 1 means full precision, the gray level must the same in \n\
155 the wall dot, whereas values close to 0 \n\
156 show a very bad precision.\n\
158 -E <ellipsoid shape precision> %f\n\
159 Precision of the ellipsoid shape of the dot. \n\
160 It is a double precision float witch value is in [0,1].\n\
161 1 means full precision, the shape should be a perfect ellipsoid,\n\
162 whereas values close to 0 show a very bad precision.\n\
163 0 means the shape of dots is not tested \n\
165 ipath.c_str(),ppath.c_str(), first, nimages, step, sizePrecision,
166 grayLevelPrecision, ellipsoidShapePrecision );
170 Disable the mouse click. Useful to automaze the \n\
171 execution of this program without humain intervention.\n\
174 Turn off the display.\n\
180 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
202 bool getOptions(
int argc,
const char **argv, std::string &ipath,
203 std::string &ppath,
unsigned &first,
unsigned &nimages,
204 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
205 double &ellipsoidShapePrecision,
bool &click_allowed,
bool &display)
212 case 'c': click_allowed =
false;
break;
213 case 'd': display =
false;
break;
214 case 'i': ipath = optarg_;
break;
215 case 'p': ppath = optarg_;
break;
216 case 'f': first = (unsigned) atoi(optarg_);
break;
217 case 'n': nimages = (unsigned) atoi(optarg_);
break;
218 case 's': step = (unsigned) atoi(optarg_);
break;
219 case 'S': sizePrecision = atof(optarg_);
break;
220 case 'G': grayLevelPrecision = atof(optarg_);
break;
221 case 'E': ellipsoidShapePrecision = atof(optarg_);
break;
222 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step,
223 sizePrecision,grayLevelPrecision,ellipsoidShapePrecision);
227 usage(argv[0], optarg_, ipath, ppath, first, nimages, step,
228 sizePrecision,grayLevelPrecision,ellipsoidShapePrecision);
233 if ((c == 1) || (c == -1)) {
235 usage(argv[0], NULL, ipath, ppath, first, nimages, step,
236 sizePrecision,grayLevelPrecision,ellipsoidShapePrecision);
237 std::cerr <<
"ERROR: " << std::endl;
238 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
247 main(
int argc,
const char ** argv)
250 std::string env_ipath;
251 std::string opt_ipath;
253 std::string opt_ppath;
255 std::string filename;
256 unsigned opt_first = 1;
257 unsigned opt_nimages = 10;
258 unsigned opt_step = 1;
259 double opt_sizePrecision = 0.65;
260 double opt_grayLevelPrecision = 0.85;
261 double opt_ellipsoidShapePrecision = 0.8;
262 bool opt_click_allowed =
true;
263 bool opt_display =
true;
266 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
271 if (! env_ipath.empty())
276 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
277 opt_step,opt_sizePrecision,opt_grayLevelPrecision,
278 opt_ellipsoidShapePrecision, opt_click_allowed, opt_display) ==
false) {
283 if (!opt_ipath.empty())
288 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
289 if (ipath != env_ipath) {
290 std::cout << std::endl
291 <<
"WARNING: " << std::endl;
292 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
293 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
294 <<
" we skip the environment variable." << std::endl;
299 if (opt_ipath.empty() && env_ipath.empty()){
300 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages,
301 opt_step,opt_sizePrecision,opt_grayLevelPrecision, opt_ellipsoidShapePrecision);
302 std::cerr << std::endl
303 <<
"ERROR:" << std::endl;
304 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
306 <<
" environment variable to specify the location of the " << std::endl
307 <<
" image path where test images are located." << std::endl << std::endl
308 <<
" Use -p <personal image path> option if you want to "<<std::endl
309 <<
" use personal images." << std::endl;
318 std::ostringstream s;
319 char cfilename[FILENAME_MAX];
320 unsigned iter = opt_first;
322 if (opt_ppath.empty()){
342 s.setf(std::ios::right, std::ios::adjustfield);
343 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
344 filename = dirname + s.str();
348 sprintf(cfilename,opt_ppath.c_str(), iter) ;
349 filename = cfilename;
358 vpCTRACE <<
"Load: " << filename << std::endl;
368 std::cerr << std::endl
369 <<
"ERROR:" << std::endl;
370 std::cerr <<
" Cannot read " << filename << std::endl;
371 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
372 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
373 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
380 #if defined VISP_HAVE_GTK
382 #elif defined VISP_HAVE_X11
384 #elif defined VISP_HAVE_GDI
390 display.
init(I, 100, 100,
"Display...") ;
404 if (opt_click_allowed & opt_display) {
407 std::cout <<
"Please click on a dot to initialize detection"
419 printf(
"Dot characteristics: \n");
420 printf(
" width : %lf\n", d.
getWidth());
422 printf(
" area: %lf\n", d.
getArea());
442 while (iter < opt_first + opt_nimages*opt_step)
447 if (opt_ppath.empty()){
450 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
451 filename = dirname + s.str();
454 sprintf(cfilename, opt_ppath.c_str(), iter) ;
455 filename = cfilename;
465 std::cout <<
"Search dots in image" << filename << std::endl;
466 std::list<vpDot2> list_d;
469 if( list_d.empty() ) {
470 std::cout <<
"Dot auto detection did not work." << std::endl;
474 std::cout << std::endl << list_d.size() <<
" dots are detected" << std::endl;
479 for (std::list<vpDot2>::const_iterator it = list_d.begin(); it != list_d.end(); ++ it)
483 std::cout <<
"Dot " << i++ <<
" : " << cog.
get_u()
484 <<
" " << cog.
get_v() << std::endl;
493 if (opt_display && opt_click_allowed) {
494 std::cout <<
"\nA click to continue..." << std::endl;
501 if (opt_display && opt_click_allowed) {
502 std::cout <<
"\nA click to exit..." << std::endl;
510 std::cout <<
"Catch an exception: " << e << std::endl;
518 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
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)
unsigned int getWidth() const
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.
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)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
unsigned int getGrayLevelMin() const
void setArea(const double &area)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void setEllipsoidShapePrecision(const double &ellipsoidShapePrecision)
void setGrayLevelMin(const unsigned int &min)
void setWidth(const double &width)
void setSizePrecision(const double &sizePrecision)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
void setHeight(const double &height)
unsigned int getHeight() const
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)
static const vpColor blue