47 #include <visp3/core/vpConfig.h>
48 #include <visp3/core/vpDebug.h>
55 #if defined(VISP_HAVE_MODULE_BLOB) && \
56 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
58 #include <visp3/blob/vpDot2.h>
59 #include <visp3/core/vpImage.h>
60 #include <visp3/core/vpImagePoint.h>
61 #include <visp3/core/vpIoTools.h>
62 #include <visp3/gui/vpDisplayGDI.h>
63 #include <visp3/gui/vpDisplayGTK.h>
64 #include <visp3/gui/vpDisplayOpenCV.h>
65 #include <visp3/gui/vpDisplayX.h>
66 #include <visp3/io/vpImageIo.h>
67 #include <visp3/io/vpParseArgv.h>
70 #define GETOPTARGS "cdi:p:f:l:s:S:G:E:h"
72 #ifdef ENABLE_VISP_NAMESPACE
93 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
94 unsigned last,
unsigned step,
double sizePrecision,
double grayLevelPrecision,
95 double ellipsoidShapePrecision)
97 #if VISP_HAVE_DATASET_VERSION >= 0x030600
98 std::string ext(
"png");
100 std::string ext(
"pgm");
103 Test auto detection of dots using vpDot2.\n\
106 %s [-i <input image path>] [-p <personal image path>]\n\
107 [-f <first image>] [-l <last image>] [-s <step>] \n\
108 [-S <size precision>] [-G <gray level precision>]\n\
109 [-E <ellipsoid shape precision>] [-c] [-d] [-h]\n",
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.%s\"\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 The format is selected by analysing the filename extension.\n\
126 Example : \"/Temp/visp-images/mire-2/image.%%04d.%s\"\n\
127 %%04d is for the image numbering.\n\
129 -f <first image> %u\n\
130 First image number of the sequence.\n\
132 -l <last image> %u\n\
133 Last image number of the sequence.\n\
136 Step between two images.\n\
138 -S <size precision> %f\n\
139 Precision of the size of the dot. \n\
140 It is a double precision float witch value is in ]0,1].\n\
141 1 means full precision, the sizes (width, heigth, surface) \n\
142 of the dots must the same, whereas values close to 0 \n\
143 show a very bad precision.\n\
145 -G <gray level precision> %f\n\
146 Precision of the gray level of the dot. \n\
147 It is a double precision float witch value is in ]0,1].\n\
148 1 means full precision, the gray level must the same in \n\
149 the wall dot, whereas values close to 0 \n\
150 show a very bad precision.\n\
152 -E <ellipsoid shape precision> %f\n\
153 Precision of the ellipsoid shape of the dot. \n\
154 It is a double precision float witch value is in [0,1].\n\
155 1 means full precision, the shape should be a perfect ellipsoid,\n\
156 whereas values close to 0 show a very bad precision.\n\
157 0 means the shape of dots is not tested \n\
159 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step, sizePrecision, grayLevelPrecision,
160 ellipsoidShapePrecision);
164 Disable the mouse click. Useful to automate the \n\
165 execution of this program without human intervention.\n\
168 Turn off the display.\n\
174 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
196 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
197 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
double &ellipsoidShapePrecision,
198 bool &click_allowed,
bool &display)
206 click_allowed =
false;
218 first = (unsigned)atoi(optarg_);
221 last = (unsigned)atoi(optarg_);
224 step = (unsigned)atoi(optarg_);
227 sizePrecision = atof(optarg_);
230 grayLevelPrecision = atof(optarg_);
233 ellipsoidShapePrecision = atof(optarg_);
236 usage(argv[0],
nullptr, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
237 ellipsoidShapePrecision);
242 usage(argv[0], optarg_, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
243 ellipsoidShapePrecision);
249 if ((c == 1) || (c == -1)) {
251 usage(argv[0],
nullptr, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
252 ellipsoidShapePrecision);
253 std::cerr <<
"ERROR: " << std::endl;
254 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
261 int main(
int argc,
const char **argv)
264 std::string env_ipath;
265 std::string opt_ipath;
267 std::string opt_ppath;
269 std::string filename;
270 unsigned opt_first = 1;
271 unsigned opt_last = 10;
272 unsigned opt_step = 1;
273 double opt_sizePrecision = 0.65;
274 double opt_grayLevelPrecision = 0.85;
275 double opt_ellipsoidShapePrecision = 0.8;
276 bool opt_click_allowed =
true;
277 bool opt_display =
true;
279 #if VISP_HAVE_DATASET_VERSION >= 0x030600
280 std::string ext(
"png");
282 std::string ext(
"pgm");
290 if (!env_ipath.empty())
294 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_sizePrecision,
295 opt_grayLevelPrecision, opt_ellipsoidShapePrecision, opt_click_allowed, opt_display) ==
false) {
300 if (!opt_ipath.empty())
305 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
306 if (ipath != env_ipath) {
307 std::cout << std::endl <<
"WARNING: " << std::endl;
308 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
309 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
310 <<
" we skip the environment variable." << std::endl;
315 if (opt_ipath.empty() && env_ipath.empty()) {
316 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step, opt_sizePrecision,
317 opt_grayLevelPrecision, opt_ellipsoidShapePrecision);
318 std::cerr << std::endl <<
"ERROR:" << std::endl;
319 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
320 <<
" environment variable to specify the location of the " << std::endl
321 <<
" image path where test images are located." << std::endl
323 <<
" Use -p <personal image path> option if you want to " << std::endl
324 <<
" use personal images." << std::endl;
332 std::ostringstream s;
333 char cfilename[FILENAME_MAX];
334 unsigned iter = opt_first;
336 if (opt_ppath.empty()) {
351 s.setf(std::ios::right, std::ios::adjustfield);
352 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
356 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
357 filename = cfilename;
365 vpCTRACE <<
"Load: " << filename << std::endl;
371 std::cerr << std::endl <<
"ERROR:" << std::endl;
372 std::cerr <<
" Cannot read " << filename << std::endl;
373 if (opt_ppath.empty()) {
374 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
375 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
378 std::cerr <<
" Check your -p " << opt_ppath <<
" option " << std::endl;
384 #if defined(VISP_HAVE_GTK)
386 #elif defined(VISP_HAVE_X11)
388 #elif defined(VISP_HAVE_GDI)
390 #elif defined(HAVE_OPENCV_HIGHGUI)
396 display.init(I, 100, 100,
"Display...");
410 if (opt_click_allowed & opt_display) {
411 d.setGrayLevelPrecision(opt_grayLevelPrecision);
413 std::cout <<
"Please click on a dot to initialize detection" << std::endl;
422 d.setSizePrecision(opt_sizePrecision);
423 d.setEllipsoidShapePrecision(opt_ellipsoidShapePrecision);
424 printf(
"Dot characteristics: \n");
425 printf(
" width : %lf\n", d.
getWidth());
427 printf(
" area: %lf\n", d.getArea());
428 printf(
" gray level min: %u\n", d.getGrayLevelMin());
429 printf(
" gray level max: %u\n", d.getGrayLevelMax());
430 printf(
" grayLevelPrecision: %lf\n", d.getGrayLevelPrecision());
431 printf(
" sizePrecision: %lf\n", d.getSizePrecision());
432 printf(
" ellipsoidShapePrecision: %lf\n", d.getEllipsoidShapePrecision());
440 d.setGrayLevelMin(164);
441 d.setGrayLevelMax(255);
442 d.setGrayLevelPrecision(opt_grayLevelPrecision);
443 d.setSizePrecision(opt_sizePrecision);
444 d.setEllipsoidShapePrecision(opt_ellipsoidShapePrecision);
447 while (iter < opt_last) {
450 if (opt_ppath.empty()) {
453 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
457 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
458 filename = cfilename;
468 std::cout <<
"Search dots in image" << filename << std::endl;
469 std::list<vpDot2> list_d;
472 if (list_d.empty()) {
473 std::cout <<
"Dot auto detection did not work." << std::endl;
477 std::cout << std::endl << list_d.size() <<
" dots are detected" << std::endl;
482 for (std::list<vpDot2>::const_iterator it = list_d.begin(); it != list_d.end(); ++it) {
485 std::cout <<
"Dot " << i++ <<
" : " << cog.
get_u() <<
" " << cog.
get_v() << std::endl;
495 if (opt_display && opt_click_allowed) {
496 std::cout <<
"\nA click to continue..." << std::endl;
503 if (opt_display && opt_click_allowed) {
504 std::cout <<
"\nA click to exit..." << std::endl;
512 std::cout <<
"Catch an exception: " << e << std::endl;
521 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display "
522 "functionalities are required..."
static const vpColor blue
static const vpColor green
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
unsigned int getHeight() const
static void flush(const vpImage< unsigned char > &I)
unsigned int getWidth() const
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
error that can be emitted by ViSP classes.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
unsigned int getHeight() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)