53 #include <visp/vpDebug.h>
54 #include <visp/vpConfig.h>
61 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
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/vpDisplayOpenCV.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;
269 if (! env_ipath.empty())
273 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
274 opt_step,opt_sizePrecision,opt_grayLevelPrecision,
275 opt_ellipsoidShapePrecision, opt_click_allowed, opt_display) ==
false) {
280 if (!opt_ipath.empty())
285 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
286 if (ipath != env_ipath) {
287 std::cout << std::endl
288 <<
"WARNING: " << std::endl;
289 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
290 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
291 <<
" we skip the environment variable." << std::endl;
296 if (opt_ipath.empty() && env_ipath.empty()){
297 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages,
298 opt_step,opt_sizePrecision,opt_grayLevelPrecision, opt_ellipsoidShapePrecision);
299 std::cerr << std::endl
300 <<
"ERROR:" << std::endl;
301 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
303 <<
" environment variable to specify the location of the " << std::endl
304 <<
" image path where test images are located." << std::endl << std::endl
305 <<
" Use -p <personal image path> option if you want to "<<std::endl
306 <<
" use personal images." << std::endl;
315 std::ostringstream s;
316 char cfilename[FILENAME_MAX];
317 unsigned iter = opt_first;
319 if (opt_ppath.empty()){
339 s.setf(std::ios::right, std::ios::adjustfield);
340 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
345 sprintf(cfilename,opt_ppath.c_str(), iter) ;
346 filename = cfilename;
355 vpCTRACE <<
"Load: " << filename << std::endl;
365 std::cerr << std::endl
366 <<
"ERROR:" << std::endl;
367 std::cerr <<
" Cannot read " << filename << std::endl;
368 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
369 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
370 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
377 #if defined VISP_HAVE_GTK
379 #elif defined VISP_HAVE_X11
381 #elif defined VISP_HAVE_GDI
383 #elif defined VISP_HAVE_OPENCV
389 display.
init(I, 100, 100,
"Display...") ;
403 if (opt_click_allowed & opt_display) {
406 std::cout <<
"Please click on a dot to initialize detection"
418 printf(
"Dot characteristics: \n");
419 printf(
" width : %lf\n", d.
getWidth());
421 printf(
" area: %lf\n", d.
getArea());
441 while (iter < opt_first + opt_nimages*opt_step)
445 if (opt_ppath.empty()){
448 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
452 sprintf(cfilename, opt_ppath.c_str(), iter) ;
453 filename = cfilename;
463 std::cout <<
"Search dots in image" << filename << std::endl;
464 std::list<vpDot2> list_d;
467 if( list_d.empty() ) {
468 std::cout <<
"Dot auto detection did not work." << std::endl;
472 std::cout << std::endl << list_d.size() <<
" dots are detected" << std::endl;
477 for (std::list<vpDot2>::const_iterator it = list_d.begin(); it != list_d.end(); ++ it)
481 std::cout <<
"Dot " << i++ <<
" : " << cog.
get_u()
482 <<
" " << cog.
get_v() << std::endl;
491 if (opt_display && opt_click_allowed) {
492 std::cout <<
"\nA click to continue..." << std::endl;
499 if (opt_display && opt_click_allowed) {
500 std::cout <<
"\nA click to exit..." << std::endl;
508 std::cout <<
"Catch an exception: " << e << std::endl;
516 vpERROR_TRACE(
"You do not have X11, GTK, GDI or OpenCV display functionalities...");
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
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)
The vpDisplayOpenCV allows to display image using the opencv library.
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 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