41#include <visp3/core/vpConfig.h>
42#include <visp3/core/vpDebug.h>
45#if defined(VISP_HAVE_MODULE_BLOB) && defined(VISP_HAVE_DISPLAY)
47#include <visp3/blob/vpDot2.h>
48#include <visp3/core/vpImage.h>
49#include <visp3/core/vpImagePoint.h>
50#include <visp3/core/vpIoTools.h>
51#include <visp3/gui/vpDisplayFactory.h>
52#include <visp3/io/vpImageIo.h>
53#include <visp3/io/vpParseArgv.h>
56#define GETOPTARGS "cdi:p:f:l:s:S:G:E:h"
58#ifdef ENABLE_VISP_NAMESPACE
62void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath,
unsigned first,
63 unsigned last,
unsigned step,
double sizePrecision,
double grayLevelPrecision,
64 double ellipsoidShapePrecision);
65bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
66 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
double &ellipsoidShapePrecision,
67 bool &click_allowed,
bool &display);
83void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath,
unsigned first,
84 unsigned last,
unsigned step,
double sizePrecision,
double grayLevelPrecision,
85 double ellipsoidShapePrecision)
87#if defined(VISP_HAVE_DATASET)
88#if VISP_HAVE_DATASET_VERSION >= 0x030600
89 std::string ext(
"png");
91 std::string ext(
"pgm");
95 std::string ext(
"png");
98Test auto detection of dots using vpDot2.\n\
101 %s [-i <input image path>] [-p <personal image path>]\n\
102 [-f <first image>] [-l <last image>] [-s <step>] \n\
103 [-S <size precision>] [-G <gray level precision>]\n\
104 [-E <ellipsoid shape precision>] [-c] [-d] [-h]\n",
109 -i <input image path> %s\n\
110 Set image input path.\n\
111 From this path read images \n\
112 \"mire-2/image.%%04d.%s\"\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 The format is selected by analyzing the filename extension.\n\
121 Example : \"/Temp/visp-images/mire-2/image.%%04d.%s\"\n\
122 %%04d is for the image numbering.\n\
124 -f <first image> %u\n\
125 First image number of the sequence.\n\
127 -l <last image> %u\n\
128 Last image number of the sequence.\n\
131 Step between two images.\n\
133 -S <size precision> %f\n\
134 Precision of the size of the dot. \n\
135 It is a double precision float witch value is in ]0,1].\n\
136 1 means full precision, the sizes (width, heigth, surface) \n\
137 of the dots must the same, whereas values close to 0 \n\
138 show a very bad precision.\n\
140 -G <gray level precision> %f\n\
141 Precision of the gray level of the dot. \n\
142 It is a double precision float witch value is in ]0,1].\n\
143 1 means full precision, the gray level must the same in \n\
144 the wall dot, whereas values close to 0 \n\
145 show a very bad precision.\n\
147 -E <ellipsoid shape precision> %f\n\
148 Precision of the ellipsoid shape of the dot. \n\
149 It is a double precision float witch value is in [0,1].\n\
150 1 means full precision, the shape should be a perfect ellipsoid,\n\
151 whereas values close to 0 show a very bad precision.\n\
152 0 means the shape of dots is not tested \n\
154ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step, sizePrecision, grayLevelPrecision,
155ellipsoidShapePrecision);
159 Disable the mouse click. Useful to automate the \n\
160 execution of this program without human intervention.\n\
163 Turn off the display.\n\
169 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
190bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
191 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
double &ellipsoidShapePrecision,
192 bool &click_allowed,
bool &display)
200 click_allowed =
false;
212 first =
static_cast<unsigned int>(atoi(optarg_));
215 last =
static_cast<unsigned int>(atoi(optarg_));
218 step =
static_cast<unsigned int>(atoi(optarg_));
221 sizePrecision = atof(optarg_);
224 grayLevelPrecision = atof(optarg_);
227 ellipsoidShapePrecision = atof(optarg_);
230 usage(argv[0],
nullptr, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
231 ellipsoidShapePrecision);
235 usage(argv[0], optarg_, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
236 ellipsoidShapePrecision);
241 if ((c == 1) || (c == -1)) {
243 usage(argv[0],
nullptr, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
244 ellipsoidShapePrecision);
245 std::cerr <<
"ERROR: " << std::endl;
246 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
253int main(
int argc,
const char **argv)
256 std::string env_ipath;
257 std::string opt_ipath;
259 std::string opt_ppath;
262 unsigned opt_first = 1;
263 unsigned opt_last = 10;
264 unsigned opt_step = 1;
265 double opt_sizePrecision = 0.65;
266 double opt_grayLevelPrecision = 0.85;
267 double opt_ellipsoidShapePrecision = 0.8;
268 bool opt_click_allowed =
true;
269 bool opt_display =
true;
271#if defined(VISP_HAVE_DATASET)
272#if VISP_HAVE_DATASET_VERSION >= 0x030600
273 std::string ext(
"png");
275 std::string ext(
"pgm");
279 std::string ext(
"png");
287 if (!env_ipath.empty())
291 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_sizePrecision,
292 opt_grayLevelPrecision, opt_ellipsoidShapePrecision, opt_click_allowed, opt_display) ==
false) {
297 if (!opt_ipath.empty())
302 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
303 if (ipath != env_ipath) {
304 std::cout << std::endl <<
"WARNING: " << std::endl;
305 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
306 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
307 <<
" we skip the environment variable." << std::endl;
312 if (opt_ipath.empty() && env_ipath.empty()) {
313 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step, opt_sizePrecision,
314 opt_grayLevelPrecision, opt_ellipsoidShapePrecision);
315 std::cerr << std::endl <<
"ERROR:" << std::endl;
316 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
317 <<
" environment variable to specify the location of the " << std::endl
318 <<
" image path where test images are located." << std::endl
320 <<
" Use -p <personal image path> option if you want to " << std::endl
321 <<
" use personal images." << std::endl;
330 unsigned iter = opt_first;
332 if (opt_ppath.empty()) {
364 std::cerr << std::endl <<
"ERROR:" << std::endl;
365 std::cerr <<
" Cannot read " <<
filename << std::endl;
366 if (opt_ppath.empty()) {
367 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
368 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
371 std::cerr <<
" Check your -p " << opt_ppath <<
" option " << std::endl;
380 display->init(I, 100, 100,
"Display...");
394 if (opt_click_allowed & opt_display) {
395 d.setGrayLevelPrecision(opt_grayLevelPrecision);
397 std::cout <<
"Please click on a dot to initialize detection" << std::endl;
406 d.setSizePrecision(opt_sizePrecision);
407 d.setEllipsoidShapePrecision(opt_ellipsoidShapePrecision);
408 printf(
"Dot characteristics: \n");
409 printf(
" width : %lf\n",
d.getWidth());
410 printf(
" height: %lf\n",
d.getHeight());
411 printf(
" area: %lf\n",
d.getArea());
412 printf(
" gray level min: %u\n",
d.getGrayLevelMin());
413 printf(
" gray level max: %u\n",
d.getGrayLevelMax());
414 printf(
" grayLevelPrecision: %lf\n",
d.getGrayLevelPrecision());
415 printf(
" sizePrecision: %lf\n",
d.getSizePrecision());
416 printf(
" ellipsoidShapePrecision: %lf\n",
d.getEllipsoidShapePrecision());
424 d.setGrayLevelMin(164);
425 d.setGrayLevelMax(255);
426 d.setGrayLevelPrecision(opt_grayLevelPrecision);
427 d.setSizePrecision(opt_sizePrecision);
428 d.setEllipsoidShapePrecision(opt_ellipsoidShapePrecision);
432 while ((iter < opt_last) && (!quit)) {
434 if (opt_ppath.empty()) {
449 std::cout <<
"Search dots in image" <<
filename << std::endl;
450 std::list<vpDot2> list_d;
451 d.searchDotsInArea(I, 0, 0, I.getWidth(), I.getHeight(), list_d);
453 if (list_d.empty()) {
454 std::cout <<
"Dot auto detection did not work." << std::endl;
458 std::cout << std::endl << list_d.size() <<
" dots are detected" << std::endl;
463 for (std::list<vpDot2>::const_iterator it = list_d.begin(); it != list_d.end(); ++it) {
466 std::cout <<
"Dot " <<
i++ <<
" : " << cog.
get_u() <<
" " << cog.
get_v() << std::endl;
470 if (opt_click_allowed) {
486 if (opt_display && opt_click_allowed && !quit) {
487 std::cout <<
"\nA click to exit..." << std::endl;
499 std::cout <<
"Catch an exception: " <<
e << std::endl;
508 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display "
509 "functionalities are required..."
static const vpColor blue
static const vpColor green
Class that defines generic functionalities for display.
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)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
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 ...
Definition of the vpImage class member functions.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.