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
76 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
77 unsigned last,
unsigned step,
double sizePrecision,
double grayLevelPrecision,
78 double ellipsoidShapePrecision)
80 #if VISP_HAVE_DATASET_VERSION >= 0x030600
81 std::string ext(
"png");
83 std::string ext(
"pgm");
86 Test auto detection of dots using vpDot2.\n\
89 %s [-i <input image path>] [-p <personal image path>]\n\
90 [-f <first image>] [-l <last image>] [-s <step>] \n\
91 [-S <size precision>] [-G <gray level precision>]\n\
92 [-E <ellipsoid shape precision>] [-c] [-d] [-h]\n",
97 -i <input image path> %s\n\
98 Set image input path.\n\
99 From this path read images \n\
100 \"mire-2/image.%%04d.%s\"\n\
101 Setting the VISP_INPUT_IMAGE_PATH environment\n\
102 variable produces the same behaviour than using\n\
105 -p <personal image path> %s\n\
106 Specify a personal sequence containing images \n\
108 The format is selected by analysing the filename extension.\n\
109 Example : \"/Temp/visp-images/mire-2/image.%%04d.%s\"\n\
110 %%04d is for the image numbering.\n\
112 -f <first image> %u\n\
113 First image number of the sequence.\n\
115 -l <last image> %u\n\
116 Last image number of the sequence.\n\
119 Step between two images.\n\
121 -S <size precision> %f\n\
122 Precision of the size of the dot. \n\
123 It is a double precision float witch value is in ]0,1].\n\
124 1 means full precision, the sizes (width, heigth, surface) \n\
125 of the dots must the same, whereas values close to 0 \n\
126 show a very bad precision.\n\
128 -G <gray level precision> %f\n\
129 Precision of the gray level of the dot. \n\
130 It is a double precision float witch value is in ]0,1].\n\
131 1 means full precision, the gray level must the same in \n\
132 the wall dot, whereas values close to 0 \n\
133 show a very bad precision.\n\
135 -E <ellipsoid shape precision> %f\n\
136 Precision of the ellipsoid shape of the dot. \n\
137 It is a double precision float witch value is in [0,1].\n\
138 1 means full precision, the shape should be a perfect ellipsoid,\n\
139 whereas values close to 0 show a very bad precision.\n\
140 0 means the shape of dots is not tested \n\
142 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step, sizePrecision, grayLevelPrecision,
143 ellipsoidShapePrecision);
147 Disable the mouse click. Useful to automate the \n\
148 execution of this program without human intervention.\n\
151 Turn off the display.\n\
157 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
179 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
180 unsigned &step,
double &sizePrecision,
double &grayLevelPrecision,
double &ellipsoidShapePrecision,
181 bool &click_allowed,
bool &display)
189 click_allowed =
false;
201 first = (unsigned)atoi(optarg_);
204 last = (unsigned)atoi(optarg_);
207 step = (unsigned)atoi(optarg_);
210 sizePrecision = atof(optarg_);
213 grayLevelPrecision = atof(optarg_);
216 ellipsoidShapePrecision = atof(optarg_);
219 usage(argv[0],
nullptr, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
220 ellipsoidShapePrecision);
225 usage(argv[0], optarg_, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
226 ellipsoidShapePrecision);
232 if ((c == 1) || (c == -1)) {
234 usage(argv[0],
nullptr, ipath, ppath, first, last, step, sizePrecision, grayLevelPrecision,
235 ellipsoidShapePrecision);
236 std::cerr <<
"ERROR: " << std::endl;
237 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
244 int main(
int argc,
const char **argv)
247 std::string env_ipath;
248 std::string opt_ipath;
250 std::string opt_ppath;
252 std::string filename;
253 unsigned opt_first = 1;
254 unsigned opt_last = 10;
255 unsigned opt_step = 1;
256 double opt_sizePrecision = 0.65;
257 double opt_grayLevelPrecision = 0.85;
258 double opt_ellipsoidShapePrecision = 0.8;
259 bool opt_click_allowed =
true;
260 bool opt_display =
true;
262 #if VISP_HAVE_DATASET_VERSION >= 0x030600
263 std::string ext(
"png");
265 std::string ext(
"pgm");
273 if (!env_ipath.empty())
277 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_sizePrecision,
278 opt_grayLevelPrecision, opt_ellipsoidShapePrecision, opt_click_allowed, opt_display) ==
false) {
283 if (!opt_ipath.empty())
288 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
289 if (ipath != env_ipath) {
290 std::cout << std::endl <<
"WARNING: " << std::endl;
291 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
292 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
293 <<
" we skip the environment variable." << std::endl;
298 if (opt_ipath.empty() && env_ipath.empty()) {
299 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step, opt_sizePrecision,
300 opt_grayLevelPrecision, opt_ellipsoidShapePrecision);
301 std::cerr << std::endl <<
"ERROR:" << std::endl;
302 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
303 <<
" environment variable to specify the location of the " << std::endl
304 <<
" image path where test images are located." << std::endl
306 <<
" Use -p <personal image path> option if you want to " << std::endl
307 <<
" use personal images." << std::endl;
316 std::ostringstream s;
317 char cfilename[FILENAME_MAX];
318 unsigned iter = opt_first;
320 if (opt_ppath.empty()) {
335 s.setf(std::ios::right, std::ios::adjustfield);
336 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
340 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
341 filename = cfilename;
349 vpCTRACE <<
"Load: " << filename << std::endl;
355 std::cerr << std::endl <<
"ERROR:" << std::endl;
356 std::cerr <<
" Cannot read " << filename << std::endl;
357 if (opt_ppath.empty()) {
358 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
359 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
362 std::cerr <<
" Check your -p " << opt_ppath <<
" option " << std::endl;
371 display->init(I, 100, 100,
"Display...");
385 if (opt_click_allowed & opt_display) {
388 std::cout <<
"Please click on a dot to initialize detection" << std::endl;
399 printf(
"Dot characteristics: \n");
400 printf(
" width : %lf\n", d.
getWidth());
402 printf(
" area: %lf\n", d.
getArea());
423 while ((iter < opt_last) && (!quit)) {
425 if (opt_ppath.empty()) {
427 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
431 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
432 filename = cfilename;
442 std::cout <<
"Search dots in image" << filename << std::endl;
443 std::list<vpDot2> list_d;
446 if (list_d.empty()) {
447 std::cout <<
"Dot auto detection did not work." << std::endl;
451 std::cout << std::endl << list_d.size() <<
" dots are detected" << std::endl;
456 for (std::list<vpDot2>::const_iterator it = list_d.begin(); it != list_d.end(); ++it) {
459 std::cout <<
"Dot " << i++ <<
" : " << cog.
get_u() <<
" " << cog.
get_v() << std::endl;
463 if (opt_click_allowed) {
479 if (opt_display && opt_click_allowed && !quit) {
480 std::cout <<
"\nA click to exit..." << std::endl;
492 std::cout <<
"Catch an exception: " << e << std::endl;
501 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display "
502 "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.
unsigned int getGrayLevelMin() const
unsigned int getGrayLevelMax() const
void setGraphics(bool activate)
double getEllipsoidShapePrecision() const
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)
void setGrayLevelMax(const unsigned int &max)
void setSizePrecision(const double &sizePrecision)
void setGrayLevelPrecision(const double &grayLevelPrecision)
void setGrayLevelMin(const unsigned int &min)
void setHeight(const double &height)
vpImagePoint getCog() const
double getSizePrecision() const
double getGrayLevelPrecision() const
void setWidth(const double &width)
void setEllipsoidShapePrecision(const double &ellipsoidShapePrecision)
void setArea(const double &area)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
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)
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.