50 #include <visp3/core/vpConfig.h> 51 #include <visp3/core/vpDebug.h> 58 #if defined(VISP_HAVE_MODULE_BLOB) && \ 59 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) 61 #include <visp3/blob/vpDot2.h> 62 #include <visp3/core/vpImage.h> 63 #include <visp3/core/vpImagePoint.h> 64 #include <visp3/core/vpIoTools.h> 65 #include <visp3/gui/vpDisplayGDI.h> 66 #include <visp3/gui/vpDisplayGTK.h> 67 #include <visp3/gui/vpDisplayOpenCV.h> 68 #include <visp3/gui/vpDisplayX.h> 69 #include <visp3/io/vpImageIo.h> 70 #include <visp3/io/vpParseArgv.h> 73 #define GETOPTARGS "cdi:p:f:n:s:S:G:E:h" 75 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
76 unsigned nimages,
unsigned step,
double sizePrecision,
double grayLevelPrecision,
77 double ellipsoidShapePrecision);
78 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
79 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
double &ellipsoidShapePrecision,
80 bool &click_allowed,
bool &display);
99 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
100 unsigned nimages,
unsigned step,
double sizePrecision,
double grayLevelPrecision,
101 double ellipsoidShapePrecision)
104 Test auto detection of dots using vpDot2.\n\ 107 %s [-i <input image path>] [-p <personal image path>]\n\ 108 [-f <first image>] [-n <number of images>] [-s <step>] \n\ 109 [-S <size precision>] [-G <gray level precision>]\n\ 110 [-E <ellipsoid shape precision>] [-c] [-d] [-h]\n", name);
114 -i <input image path> %s\n\ 115 Set image input path.\n\ 116 From this path read images \n\ 117 \"mire-2/image.%%04d.pgm\"\n\ 118 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 119 variable produces the same behaviour than using\n\ 122 -p <personal image path> %s\n\ 123 Specify a personal sequence containing images \n\ 125 By image sequence, we mean one file per image.\n\ 126 The following image file formats PNM (PGM P5, PPM P6)\n\ 127 are supported. The format is selected by analysing \n\ 128 the filename extension.\n\ 129 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\ 130 %%04d is for the image numbering.\n\ 132 -f <first image> %u\n\ 133 First image number of the sequence.\n\ 135 -n <number of images> %u\n\ 136 Number of images to load from the sequence.\n\ 139 Step between two images.\n\ 141 -S <size precision> %f\n\ 142 Precision of the size of the dot. \n\ 143 It is a double precision float witch value is in ]0,1].\n\ 144 1 means full precision, the sizes (width, heigth, surface) \n\ 145 of the dots must the same, whereas values close to 0 \n\ 146 show a very bad precision.\n\ 148 -G <gray level precision> %f\n\ 149 Precision of the gray level of the dot. \n\ 150 It is a double precision float witch value is in ]0,1].\n\ 151 1 means full precision, the gray level must the same in \n\ 152 the wall dot, whereas values close to 0 \n\ 153 show a very bad precision.\n\ 155 -E <ellipsoid shape precision> %f\n\ 156 Precision of the ellipsoid shape of the dot. \n\ 157 It is a double precision float witch value is in [0,1].\n\ 158 1 means full precision, the shape should be a perfect ellipsoid,\n\ 159 whereas values close to 0 show a very bad precision.\n\ 160 0 means the shape of dots is not tested \n\ 161 \n", ipath.c_str(), ppath.c_str(), first, nimages, step, sizePrecision, grayLevelPrecision,
162 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, std::string &ppath,
unsigned &first,
unsigned &nimages,
199 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
double &ellipsoidShapePrecision,
200 bool &click_allowed,
bool &display)
208 click_allowed =
false;
220 first = (unsigned)atoi(optarg_);
223 nimages = (unsigned)atoi(optarg_);
226 step = (unsigned)atoi(optarg_);
229 sizePrecision = atof(optarg_);
232 grayLevelPrecision = atof(optarg_);
235 ellipsoidShapePrecision = atof(optarg_);
238 usage(argv[0], NULL, ipath, ppath, first, nimages, step, sizePrecision, grayLevelPrecision,
239 ellipsoidShapePrecision);
244 usage(argv[0], optarg_, ipath, ppath, first, nimages, step, sizePrecision, grayLevelPrecision,
245 ellipsoidShapePrecision);
251 if ((c == 1) || (c == -1)) {
253 usage(argv[0], NULL, ipath, ppath, first, nimages, step, sizePrecision, grayLevelPrecision,
254 ellipsoidShapePrecision);
255 std::cerr <<
"ERROR: " << std::endl;
256 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
263 int main(
int argc,
const char **argv)
266 std::string env_ipath;
267 std::string opt_ipath;
269 std::string opt_ppath;
271 std::string filename;
272 unsigned opt_first = 1;
273 unsigned opt_nimages = 10;
274 unsigned opt_step = 1;
275 double opt_sizePrecision = 0.65;
276 double opt_grayLevelPrecision = 0.85;
277 double opt_ellipsoidShapePrecision = 0.8;
278 bool opt_click_allowed =
true;
279 bool opt_display =
true;
286 if (!env_ipath.empty())
290 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_sizePrecision,
291 opt_grayLevelPrecision, opt_ellipsoidShapePrecision, opt_click_allowed, opt_display) ==
false) {
296 if (!opt_ipath.empty())
301 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
302 if (ipath != env_ipath) {
303 std::cout << std::endl <<
"WARNING: " << std::endl;
304 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 305 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
306 <<
" we skip the environment variable." << std::endl;
311 if (opt_ipath.empty() && env_ipath.empty()) {
312 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_sizePrecision,
313 opt_grayLevelPrecision, opt_ellipsoidShapePrecision);
314 std::cerr << std::endl <<
"ERROR:" << std::endl;
315 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
316 <<
" environment variable to specify the location of the " << std::endl
317 <<
" image path where test images are located." << std::endl
319 <<
" Use -p <personal image path> option if you want to " << std::endl
320 <<
" use personal images." << std::endl;
328 std::ostringstream s;
329 char cfilename[FILENAME_MAX];
330 unsigned iter = opt_first;
332 if (opt_ppath.empty()) {
351 s.setf(std::ios::right, std::ios::adjustfield);
352 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
356 sprintf(cfilename, opt_ppath.c_str(), iter);
357 filename = cfilename;
366 vpCTRACE <<
"Load: " << filename << std::endl;
374 std::cerr << std::endl <<
"ERROR:" << std::endl;
375 std::cerr <<
" Cannot read " << filename << std::endl;
376 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
377 <<
" or your -p " << opt_ppath <<
" option " << std::endl
378 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
383 #if defined VISP_HAVE_GTK 385 #elif defined VISP_HAVE_X11 387 #elif defined VISP_HAVE_GDI 389 #elif defined VISP_HAVE_OPENCV 395 display.
init(I, 100, 100,
"Display...");
409 if (opt_click_allowed & opt_display) {
412 std::cout <<
"Please click on a dot to initialize detection" << std::endl;
423 printf(
"Dot characteristics: \n");
424 printf(
" width : %lf\n", d.
getWidth());
426 printf(
" area: %lf\n", d.
getArea());
445 while (iter < opt_first + opt_nimages * opt_step) {
448 if (opt_ppath.empty()) {
451 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
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;
473 std::cout << std::endl << list_d.size() <<
" dots are detected" << std::endl;
478 for (std::list<vpDot2>::const_iterator it = list_d.begin(); it != list_d.end(); ++it) {
481 std::cout <<
"Dot " << i++ <<
" : " << cog.
get_u() <<
" " << 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;
507 std::cout <<
"Catch an exception: " << e << std::endl;
516 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display " 517 "functionalities are required..."
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).
void setGraphics(bool activate)
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
static const vpColor blue