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"
94 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
95 unsigned first,
unsigned nimages,
unsigned step,
double sizePrecision,
96 double grayLevelPrecision,
double ellipsoidShapePrecision )
99 Test auto detection of dots using vpDot2.\n\
102 %s [-i <input image path>] [-p <personal image path>]\n\
103 [-f <first image>] [-n <number of images>] [-s <step>] \n\
104 [-S <size precision>] [-G <gray level precision>]\n\
105 [-E <ellipsoid shape precision>] [-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\"\n\
113 Setting the VISP_INPUT_IMAGE_PATH environment\n\
114 variable produces the same behaviour than using\n\
117 -p <personal image path> %s\n\
118 Specify a personal sequence containing images \n\
120 By image sequence, we mean one file per image.\n\
121 The following image file formats PNM (PGM P5, PPM P6)\n\
122 are supported. The format is selected by analysing \n\
123 the filename extension.\n\
124 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
125 %%04d is for the image numbering.\n\
127 -f <first image> %u\n\
128 First image number of the sequence.\n\
130 -n <number of images> %u\n\
131 Number of images to load from the sequence.\n\
134 Step between two images.\n\
136 -S <size precision> %f\n\
137 Precision of the size of the dot. \n\
138 It is a double precision float witch value is in ]0,1].\n\
139 1 means full precision, the sizes (width, heigth, surface) \n\
140 of the dots must the same, whereas values close to 0 \n\
141 show a very bad precision.\n\
143 -G <gray level precision> %f\n\
144 Precision of the gray level of the dot. \n\
145 It is a double precision float witch value is in ]0,1].\n\
146 1 means full precision, the gray level must the same in \n\
147 the wall dot, whereas values close to 0 \n\
148 show a very bad precision.\n\
150 -E <ellipsoid shape precision> %f\n\
151 Precision of the ellipsoid shape of the dot. \n\
152 It is a double precision float witch value is in [0,1].\n\
153 1 means full precision, the shape should be a perfect ellipsoid,\n\
154 whereas values close to 0 show a very bad precision.\n\
155 0 means the shape of dots is not tested \n\
157 ipath.c_str(),ppath.c_str(), first, nimages, step, sizePrecision,
158 grayLevelPrecision, ellipsoidShapePrecision );
162 Disable the mouse click. Useful to automaze the \n\
163 execution of this program without humain intervention.\n\
166 Turn off the display.\n\
172 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
194 bool getOptions(
int argc,
const char **argv, std::string &ipath,
195 std::string &ppath,
unsigned &first,
unsigned &nimages,
196 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
197 double &ellipsoidShapePrecision,
bool &click_allowed,
bool &display)
204 case 'c': click_allowed =
false;
break;
205 case 'd': display =
false;
break;
206 case 'i': ipath = optarg;
break;
207 case 'p': ppath = optarg;
break;
208 case 'f': first = (unsigned) atoi(optarg);
break;
209 case 'n': nimages = (unsigned) atoi(optarg);
break;
210 case 's': step = (unsigned) atoi(optarg);
break;
211 case 'S': sizePrecision = atof(optarg);
break;
212 case 'G': grayLevelPrecision = atof(optarg);
break;
213 case 'E': ellipsoidShapePrecision = atof(optarg);
break;
214 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step,
215 sizePrecision,grayLevelPrecision,ellipsoidShapePrecision);
219 usage(argv[0], optarg, ipath, ppath, first, nimages, step,
220 sizePrecision,grayLevelPrecision,ellipsoidShapePrecision);
225 if ((c == 1) || (c == -1)) {
227 usage(argv[0], NULL, ipath, ppath, first, nimages, step,
228 sizePrecision,grayLevelPrecision,ellipsoidShapePrecision);
229 std::cerr <<
"ERROR: " << std::endl;
230 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
239 main(
int argc,
const char ** argv)
241 std::string env_ipath;
242 std::string opt_ipath;
244 std::string opt_ppath;
246 std::string filename;
247 unsigned opt_first = 1;
248 unsigned opt_nimages = 10;
249 unsigned opt_step = 1;
250 double opt_sizePrecision = 0.65;
251 double opt_grayLevelPrecision = 0.85;
252 double opt_ellipsoidShapePrecision = 0.8;
253 bool opt_click_allowed =
true;
254 bool opt_display =
true;
257 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
262 if (! env_ipath.empty())
267 if (getOptions(argc, argv, opt_ipath, opt_ppath,opt_first, opt_nimages,
268 opt_step,opt_sizePrecision,opt_grayLevelPrecision,
269 opt_ellipsoidShapePrecision, opt_click_allowed, opt_display) ==
false) {
274 if (!opt_ipath.empty())
279 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
280 if (ipath != env_ipath) {
281 std::cout << std::endl
282 <<
"WARNING: " << std::endl;
283 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
284 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
285 <<
" we skip the environment variable." << std::endl;
290 if (opt_ipath.empty() && env_ipath.empty()){
291 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages,
292 opt_step,opt_sizePrecision,opt_grayLevelPrecision, opt_ellipsoidShapePrecision);
293 std::cerr << std::endl
294 <<
"ERROR:" << std::endl;
295 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
297 <<
" environment variable to specify the location of the " << std::endl
298 <<
" image path where test images are located." << std::endl << std::endl
299 <<
" Use -p <personal image path> option if you want to "<<std::endl
300 <<
" use personal images." << std::endl;
309 std::ostringstream s;
310 char cfilename[FILENAME_MAX];
311 unsigned iter = opt_first;
313 if (opt_ppath.empty()){
333 s.setf(std::ios::right, std::ios::adjustfield);
334 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
335 filename = dirname + s.str();
339 sprintf(cfilename,opt_ppath.c_str(), iter) ;
340 filename = cfilename;
349 vpCTRACE <<
"Load: " << filename << std::endl;
359 std::cerr << std::endl
360 <<
"ERROR:" << std::endl;
361 std::cerr <<
" Cannot read " << filename << std::endl;
362 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
363 <<
" or your -p " << opt_ppath <<
" option " <<std::endl
364 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
371 #if defined VISP_HAVE_GTK
373 #elif defined VISP_HAVE_X11
375 #elif defined VISP_HAVE_GDI
382 display.
init(I, 100, 100,
"Display...") ;
402 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());
430 std::cerr <<
"Cannot initialize the tracking..."<< std::endl;
447 while (iter < opt_first + opt_nimages*opt_step)
452 if (opt_ppath.empty()){
455 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
456 filename = dirname + s.str();
459 sprintf(cfilename, opt_ppath.c_str(), iter) ;
460 filename = cfilename;
470 std::cout <<
"Search dots in image" << filename << std::endl;
471 std::list<vpDot2> list_d;
474 if( list_d.empty() ) {
475 std::cout <<
"Dot auto detection did not work." << std::endl;
479 std::cout << std::endl << list_d.size() <<
" dots are detected" << std::endl;
484 for (std::list<vpDot2>::const_iterator it = list_d.begin(); it != list_d.end(); ++ it)
488 std::cout <<
"Dot " << i++ <<
" : " << cog.
get_u()
489 <<
" " << cog.
get_v() << std::endl;
498 if (opt_display && opt_click_allowed) {
499 std::cout <<
"\nA click to continue..." << std::endl;
506 if (opt_display && opt_click_allowed) {
507 std::cout <<
"\nA click to exit..." << std::endl;
517 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
double getSurface() const
Display for windows using GDI (available on any windows 32 platform).
double getGrayLevelPrecision() const
Define the X11 console to display images.
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
void setSurface(const double &surface)
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 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