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"
89 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
90 unsigned last,
unsigned step,
double sizePrecision,
double grayLevelPrecision,
91 double ellipsoidShapePrecision)
93 #if VISP_HAVE_DATASET_VERSION >= 0x030600
94 std::string ext(
"png");
96 std::string ext(
"pgm");
99 Test auto detection of dots using vpDot2.\n\
102 %s [-i <input image path>] [-p <personal image path>]\n\
103 [-f <first image>] [-l <last image>] [-s <step>] \n\
104 [-S <size precision>] [-G <gray level precision>]\n\
105 [-E <ellipsoid shape precision>] [-c] [-d] [-h]\n",
110 -i <input image path> %s\n\
111 Set image input path.\n\
112 From this path read images \n\
113 \"mire-2/image.%%04d.%s\"\n\
114 Setting the VISP_INPUT_IMAGE_PATH environment\n\
115 variable produces the same behaviour than using\n\
118 -p <personal image path> %s\n\
119 Specify a personal sequence containing images \n\
121 The format is selected by analysing the filename extension.\n\
122 Example : \"/Temp/visp-images/mire-2/image.%%04d.%s\"\n\
123 %%04d is for the image numbering.\n\
125 -f <first image> %u\n\
126 First image number of the sequence.\n\
128 -l <last image> %u\n\
129 Last image number of the sequence.\n\
132 Step between two images.\n\
134 -S <size precision> %f\n\
135 Precision of the size of the dot. \n\
136 It is a double precision float witch value is in ]0,1].\n\
137 1 means full precision, the sizes (width, heigth, surface) \n\
138 of the dots must the same, whereas values close to 0 \n\
139 show a very bad precision.\n\
141 -G <gray level precision> %f\n\
142 Precision of the gray level of the dot. \n\
143 It is a double precision float witch value is in ]0,1].\n\
144 1 means full precision, the gray level must the same in \n\
145 the wall dot, whereas values close to 0 \n\
146 show a very bad precision.\n\
148 -E <ellipsoid shape precision> %f\n\
149 Precision of the ellipsoid shape of the dot. \n\
150 It is a double precision float witch value is in [0,1].\n\
151 1 means full precision, the shape should be a perfect ellipsoid,\n\
152 whereas values close to 0 show a very bad precision.\n\
153 0 means the shape of dots is not tested \n\
155 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step, sizePrecision, grayLevelPrecision,
156 ellipsoidShapePrecision);
160 Disable the mouse click. Useful to automate the \n\
161 execution of this program without human intervention.\n\
164 Turn off the display.\n\
170 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
192 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
193 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
double &ellipsoidShapePrecision,
194 bool &click_allowed,
bool &display)
202 click_allowed =
false;
214 first = (unsigned)atoi(optarg_);
217 last = (unsigned)atoi(optarg_);
220 step = (unsigned)atoi(optarg_);
223 sizePrecision = atof(optarg_);
226 grayLevelPrecision = atof(optarg_);
229 ellipsoidShapePrecision = atof(optarg_);
232 usage(argv[0],
nullptr, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
233 ellipsoidShapePrecision);
238 usage(argv[0], optarg_, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
239 ellipsoidShapePrecision);
245 if ((c == 1) || (c == -1)) {
247 usage(argv[0],
nullptr, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
248 ellipsoidShapePrecision);
249 std::cerr <<
"ERROR: " << std::endl;
250 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
257 int main(
int argc,
const char **argv)
260 std::string env_ipath;
261 std::string opt_ipath;
263 std::string opt_ppath;
265 std::string filename;
266 unsigned opt_first = 1;
267 unsigned opt_last = 10;
268 unsigned opt_step = 1;
269 double opt_sizePrecision = 0.65;
270 double opt_grayLevelPrecision = 0.85;
271 double opt_ellipsoidShapePrecision = 0.8;
272 bool opt_click_allowed =
true;
273 bool opt_display =
true;
275 #if VISP_HAVE_DATASET_VERSION >= 0x030600
276 std::string ext(
"png");
278 std::string ext(
"pgm");
286 if (!env_ipath.empty())
290 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, 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],
nullptr, ipath, opt_ppath, opt_first, opt_last, 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()) {
347 s.setf(std::ios::right, std::ios::adjustfield);
348 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
351 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
352 filename = cfilename;
360 vpCTRACE <<
"Load: " << filename << std::endl;
365 std::cerr << std::endl <<
"ERROR:" << std::endl;
366 std::cerr <<
" Cannot read " << filename << std::endl;
367 if (opt_ppath.empty()) {
368 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
369 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
372 std::cerr <<
" Check your -p " << opt_ppath <<
" option " << std::endl;
378 #if defined(VISP_HAVE_GTK)
380 #elif defined(VISP_HAVE_X11)
382 #elif defined(VISP_HAVE_GDI)
384 #elif defined(HAVE_OPENCV_HIGHGUI)
390 display.init(I, 100, 100,
"Display...");
404 if (opt_click_allowed & opt_display) {
405 d.setGrayLevelPrecision(opt_grayLevelPrecision);
407 std::cout <<
"Please click on a dot to initialize detection" << std::endl;
416 d.setSizePrecision(opt_sizePrecision);
417 d.setEllipsoidShapePrecision(opt_ellipsoidShapePrecision);
418 printf(
"Dot characteristics: \n");
419 printf(
" width : %lf\n", d.
getWidth());
421 printf(
" area: %lf\n", d.getArea());
422 printf(
" gray level min: %u\n", d.getGrayLevelMin());
423 printf(
" gray level max: %u\n", d.getGrayLevelMax());
424 printf(
" grayLevelPrecision: %lf\n", d.getGrayLevelPrecision());
425 printf(
" sizePrecision: %lf\n", d.getSizePrecision());
426 printf(
" ellipsoidShapePrecision: %lf\n", d.getEllipsoidShapePrecision());
433 d.setGrayLevelMin(164);
434 d.setGrayLevelMax(255);
435 d.setGrayLevelPrecision(opt_grayLevelPrecision);
436 d.setSizePrecision(opt_sizePrecision);
437 d.setEllipsoidShapePrecision(opt_ellipsoidShapePrecision);
440 while (iter < opt_last) {
443 if (opt_ppath.empty()) {
446 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
449 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
450 filename = cfilename;
460 std::cout <<
"Search dots in image" << filename << std::endl;
461 std::list<vpDot2> list_d;
464 if (list_d.empty()) {
465 std::cout <<
"Dot auto detection did not work." << std::endl;
469 std::cout << std::endl << list_d.size() <<
" dots are detected" << std::endl;
474 for (std::list<vpDot2>::const_iterator it = list_d.begin(); it != list_d.end(); ++it) {
477 std::cout <<
"Dot " << i++ <<
" : " << cog.
get_u() <<
" " << cog.
get_v() << std::endl;
487 if (opt_display && opt_click_allowed) {
488 std::cout <<
"\nA click to continue..." << std::endl;
495 if (opt_display && opt_click_allowed) {
496 std::cout <<
"\nA click to exit..." << std::endl;
503 std::cout <<
"Catch an exception: " << e << std::endl;
512 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display "
513 "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...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.