41 #include <visp3/core/vpConfig.h>
42 #include <visp3/core/vpDebug.h>
49 #if defined(VISP_HAVE_MODULE_BLOB) && \
50 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
52 #include <visp3/blob/vpDot2.h>
53 #include <visp3/core/vpImage.h>
54 #include <visp3/core/vpImagePoint.h>
55 #include <visp3/core/vpIoTools.h>
56 #include <visp3/gui/vpDisplayGDI.h>
57 #include <visp3/gui/vpDisplayGTK.h>
58 #include <visp3/gui/vpDisplayOpenCV.h>
59 #include <visp3/gui/vpDisplayX.h>
60 #include <visp3/io/vpImageIo.h>
61 #include <visp3/io/vpParseArgv.h>
64 #define GETOPTARGS "cdf:i:l:p:s:h"
84 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
85 unsigned last,
unsigned step)
87 #if VISP_HAVE_DATASET_VERSION >= 0x030600
88 std::string ext(
"png");
90 std::string ext(
"pgm");
93 Test dot tracking using vpDot2 class.\n\
96 %s [-i <test image path>] [-p <personal image path>]\n\
97 [-f <first image>] [-l <last image>] [-s <step>]\n\
103 -i <input image path> %s\n\
104 Set image input path.\n\
105 From this path read images \n\
106 \"mire-2/image.%%04d.%s\". These \n\
107 images come from visp-images-x.y.z.tar.gz available \n\
108 on the ViSP website.\n\
109 Setting the VISP_INPUT_IMAGE_PATH environment\n\
110 variable produces the same behaviour than using\n\
113 -p <personal image path> %s\n\
114 Specify a personal sequence containing images \n\
116 By image sequence, we mean one file per image.\n\
117 Example : \"C:/Temp/visp-images/cube/image.%%04d.%s\"\n\
118 %%04d is for the image numbering.\n\
120 -f <first image> %u\n\
121 First image number of the sequence.\n\
123 -l <last image> %u\n\
124 Last image number of the sequence.\n\
127 Step between two images.\n\
130 Disable the mouse click. Useful to automate the \n\
131 execution of this program without human intervention.\n\
134 Turn off the display.\n\
138 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
141 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
160 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
161 unsigned &step,
bool &click_allowed,
bool &display)
169 click_allowed =
false;
181 first = (unsigned)atoi(optarg_);
184 last = (unsigned)atoi(optarg_);
187 step = (unsigned)atoi(optarg_);
190 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
195 usage(argv[0], optarg_, ipath, ppath, first, last, step);
201 if ((c == 1) || (c == -1)) {
203 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
204 std::cerr <<
"ERROR: " << std::endl;
205 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
212 int main(
int argc,
const char **argv)
215 std::string env_ipath;
216 std::string opt_ipath;
218 std::string opt_ppath;
220 std::string filename;
221 unsigned opt_first = 1;
222 unsigned opt_last = 500;
223 unsigned opt_step = 1;
224 bool opt_click_allowed =
true;
225 bool opt_display =
true;
227 #if VISP_HAVE_DATASET_VERSION >= 0x030600
228 std::string ext(
"png");
230 std::string ext(
"pgm");
238 if (!env_ipath.empty())
242 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_click_allowed,
243 opt_display) ==
false) {
248 if (!opt_ipath.empty())
253 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
254 if (ipath != env_ipath) {
255 std::cout << std::endl <<
"WARNING: " << std::endl;
256 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
257 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
258 <<
" we skip the environment variable." << std::endl;
263 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
264 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
265 std::cerr << std::endl <<
"ERROR:" << std::endl;
266 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
267 <<
" environment variable to specify the location of the " << std::endl
268 <<
" image path where test images are located." << std::endl
269 <<
" Use -p <personal image path> option if you want to " << std::endl
270 <<
" use personal images." << std::endl
281 unsigned iter = opt_first;
282 std::ostringstream s;
283 char cfilename[FILENAME_MAX];
285 if (opt_ppath.empty()) {
300 s.setf(std::ios::right, std::ios::adjustfield);
301 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
304 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
305 filename = cfilename;
314 vpCTRACE <<
"Load: " << filename << std::endl;
319 std::cerr << std::endl <<
"ERROR:" << std::endl;
320 std::cerr <<
" Cannot read " << filename << std::endl;
321 if (opt_ppath.empty()) {
322 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
323 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
326 std::cerr <<
" Check your -p " << opt_ppath <<
" option " << std::endl;
332 #if defined(VISP_HAVE_X11)
334 #elif defined(VISP_HAVE_GTK)
336 #elif defined(VISP_HAVE_GDI)
338 #elif defined(HAVE_OPENCV_HIGHGUI)
344 display.init(I, 100, 100,
"Display...");
372 d.setGraphics(
false);
377 d.setComputeMoments(
true);
378 d.setGrayLevelPrecision(0.90);
386 if (opt_display && opt_click_allowed) {
387 std::cout <<
"Click on a dot to track it." << std::endl;
393 d.initTracking(I, ip);
396 std::cout <<
"COG: " << std::endl;
398 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v() << std::endl;
399 std::cout <<
"Size:" << std::endl;
401 std::cout <<
"Area: " << d.getArea() << std::endl;
402 std::cout <<
"Centered normalized moments nij:" << std::endl;
403 std::cout <<
" n20: " << d.get_nij()[0] << std::endl;
404 std::cout <<
" n11: " << d.get_nij()[1] << std::endl;
405 std::cout <<
" n02: " << d.get_nij()[2] << std::endl;
406 std::cout <<
"Settings:" << std::endl;
407 std::cout <<
" gray level min: " << d.getGrayLevelMin() << std::endl;
408 std::cout <<
" gray level max: " << d.getGrayLevelMax() << std::endl;
409 std::cout <<
" size precision: " << d.getSizePrecision() << std::endl;
410 std::cout <<
" gray level precision: " << d.getGrayLevelPrecision() << std::endl;
413 while (iter < opt_last) {
415 if (opt_ppath.empty()) {
417 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
420 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
421 filename = cfilename;
424 std::cout <<
"read : " << filename << std::endl;
438 std::cout <<
"Tracking on image: " << filename << std::endl;
444 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v() << std::endl;
445 std::cout <<
"Size:" << std::endl;
447 std::cout <<
"Area: " << d.getArea() << std::endl;
448 std::cout <<
"Centered normalized moments nij:" << std::endl;
449 std::cout <<
" n20: " << d.get_nij()[0] << std::endl;
450 std::cout <<
" n11: " << d.get_nij()[1] << std::endl;
451 std::cout <<
" n02: " << d.get_nij()[2] << std::endl;
452 std::cout <<
"Settings:" << std::endl;
453 std::cout <<
" gray level min: " << d.getGrayLevelMin() << std::endl;
454 std::cout <<
" gray level max: " << d.getGrayLevelMax() << std::endl;
455 std::cout <<
" size precision: " << d.getSizePrecision() << std::endl;
456 std::cout <<
" gray level precision: " << d.getGrayLevelPrecision() << std::endl;
460 std::list<vpImagePoint> edges;
462 std::list<vpImagePoint>::const_iterator it;
463 for (it = edges.begin(); it != edges.end(); ++it) {
478 if (opt_display && opt_click_allowed) {
479 std::cout <<
"\nA click to exit..." << std::endl;
485 std::cout <<
"Catch an exception: " << e << std::endl;
494 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display "
495 "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)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
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 ...
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.
VISP_EXPORT double measureTimeMs()