45 #include <visp3/core/vpConfig.h> 46 #include <visp3/core/vpDebug.h> 53 #if defined(VISP_HAVE_MODULE_BLOB) && \ 54 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) 56 #include <visp3/blob/vpDot2.h> 57 #include <visp3/core/vpImage.h> 58 #include <visp3/core/vpImagePoint.h> 59 #include <visp3/core/vpIoTools.h> 60 #include <visp3/gui/vpDisplayGDI.h> 61 #include <visp3/gui/vpDisplayGTK.h> 62 #include <visp3/gui/vpDisplayOpenCV.h> 63 #include <visp3/gui/vpDisplayX.h> 64 #include <visp3/io/vpImageIo.h> 65 #include <visp3/io/vpParseArgv.h> 68 #define GETOPTARGS "cdf:i:n:p:s:h" 72 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
73 unsigned nimages,
unsigned step);
74 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
75 unsigned &step,
bool &click_allowed,
bool &display);
95 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
96 unsigned nimages,
unsigned step)
99 Test dot tracking using vpDot2 class.\n\ 102 %s [-i <test image path>] [-p <personal image path>]\n\ 103 [-f <first image>] [-n <number of images>] [-s <step>]\n\ 104 [-c] [-d] [-h]\n", name);
108 -i <input image path> %s\n\ 109 Set image input path.\n\ 110 From this path read images \n\ 111 \"mire-2/image.%%04d.pgm\". These \n\ 112 images come from ViSP-images-x.y.z.tar.gz available \n\ 113 on the ViSP website.\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 By image sequence, we mean one file per image.\n\ 122 The following image file formats PNM (PGM P5, PPM P6)\n\ 123 are supported. The format is selected by analysing \n\ 124 the filename extension.\n\ 125 Example : \"C:/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\ 126 %%04d is for the image numbering.\n\ 128 -f <first image> %u\n\ 129 First image number of the sequence.\n\ 131 -n <number of images> %u\n\ 132 Number of images to load from the sequence.\n\ 135 Step between two images.\n\ 138 Disable the mouse click. Useful to automaze the \n\ 139 execution of this program without humain intervention.\n\ 142 Turn off the display.\n\ 145 Print the help.\n", ipath.c_str(), ppath.c_str(), first, nimages, step);
148 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
167 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
168 unsigned &step,
bool &click_allowed,
bool &display)
176 click_allowed =
false;
188 first = (unsigned)atoi(optarg_);
191 nimages = (unsigned)atoi(optarg_);
194 step = (unsigned)atoi(optarg_);
197 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
202 usage(argv[0], optarg_, ipath, ppath, first, nimages, step);
208 if ((c == 1) || (c == -1)) {
210 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
211 std::cerr <<
"ERROR: " << std::endl;
212 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
219 int main(
int argc,
const char **argv)
222 std::string env_ipath;
223 std::string opt_ipath;
225 std::string opt_ppath;
227 std::string filename;
228 unsigned opt_first = 1;
229 unsigned opt_nimages = 500;
230 unsigned opt_step = 1;
231 bool opt_click_allowed =
true;
232 bool opt_display =
true;
239 if (!env_ipath.empty())
243 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_click_allowed,
244 opt_display) ==
false) {
249 if (!opt_ipath.empty())
254 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
255 if (ipath != env_ipath) {
256 std::cout << std::endl <<
"WARNING: " << std::endl;
257 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 258 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
259 <<
" we skip the environment variable." << std::endl;
264 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
265 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
266 std::cerr << std::endl <<
"ERROR:" << std::endl;
267 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
268 <<
" environment variable to specify the location of the " << std::endl
269 <<
" image path where test images are located." << std::endl
270 <<
" Use -p <personal image path> option if you want to " << std::endl
271 <<
" use personal images." << std::endl
282 unsigned iter = opt_first;
283 std::ostringstream s;
284 char cfilename[FILENAME_MAX];
286 if (opt_ppath.empty()) {
305 s.setf(std::ios::right, std::ios::adjustfield);
306 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
310 sprintf(cfilename, opt_ppath.c_str(), iter);
311 filename = cfilename;
321 vpCTRACE <<
"Load: " << filename << std::endl;
329 std::cerr << std::endl <<
"ERROR:" << std::endl;
330 std::cerr <<
" Cannot read " << filename << std::endl;
331 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
332 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
337 #if defined VISP_HAVE_X11 339 #elif defined VISP_HAVE_GTK 341 #elif defined VISP_HAVE_GDI 343 #elif defined VISP_HAVE_OPENCV 349 display.
init(I, 100, 100,
"Display...");
391 if (opt_display && opt_click_allowed) {
392 std::cout <<
"Click on a dot to track it." << std::endl;
401 std::cout <<
"COG: " << std::endl;
403 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v() <<
" - " << d.
m10 / d.
m00 <<
" " << d.
m01 / d.
m00 405 std::cout <<
"Size:" << std::endl;
407 std::cout <<
"Area: " << d.
getArea() << std::endl;
408 std::cout <<
"Moments:" << std::endl;
409 std::cout <<
" m00: " << d.
m00 << std::endl;
410 std::cout <<
" m10: " << d.
m10 << std::endl;
411 std::cout <<
" m01: " << d.
m01 << std::endl;
412 std::cout <<
" m11: " << d.
m11 << std::endl;
413 std::cout <<
" m02: " << d.
m02 << std::endl;
414 std::cout <<
" m20: " << d.
m20 << std::endl;
415 std::cout <<
"Centered moments:" << std::endl;
416 std::cout <<
" mu11: " << d.
mu11 << std::endl;
417 std::cout <<
" mu02: " << d.
mu02 << std::endl;
418 std::cout <<
" mu20: " << d.
mu20 << std::endl;
419 std::cout <<
"Settings:" << std::endl;
426 while (iter < opt_first + opt_nimages * opt_step) {
428 if (opt_ppath.empty()) {
430 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
433 sprintf(cfilename, opt_ppath.c_str(), iter);
434 filename = cfilename;
437 std::cout <<
"read : " << filename << std::endl;
451 std::cout <<
"Tracking on image: " << filename << std::endl;
457 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v() <<
" - " << d.
m10 / d.
m00 <<
" " << d.
m01 / d.
m00 459 std::cout <<
"Size:" << std::endl;
461 std::cout <<
"Area: " << d.
getArea() << std::endl;
462 std::cout <<
"Moments:" << std::endl;
463 std::cout <<
" m00: " << d.
m00 << std::endl;
464 std::cout <<
" m10: " << d.
m10 << std::endl;
465 std::cout <<
" m01: " << d.
m01 << std::endl;
466 std::cout <<
" m11: " << d.
m11 << std::endl;
467 std::cout <<
" m02: " << d.
m02 << std::endl;
468 std::cout <<
" m20: " << d.
m20 << std::endl;
469 std::cout <<
"Centered moments:" << std::endl;
470 std::cout <<
" mu11: " << d.
mu11 << std::endl;
471 std::cout <<
" mu02: " << d.
mu02 << std::endl;
472 std::cout <<
" mu20: " << d.
mu20 << std::endl;
473 std::cout <<
"Settings:" << std::endl;
481 std::list<vpImagePoint> edges;
483 std::list<vpImagePoint>::const_iterator it;
484 for (it = edges.begin(); it != edges.end(); ++it) {
499 if (opt_display && opt_click_allowed) {
500 std::cout <<
"\nA click to exit..." << std::endl;
506 std::cout <<
"Catch an exception: " << e << std::endl;
515 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display " 516 "functionalities are required..."
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
double getGrayLevelPrecision() const
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static const vpColor green
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
void track(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
double getSizePrecision() const
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
vpImagePoint getCog() const
void setGrayLevelPrecision(const double &grayLevelPrecision)
void set_u(const double u)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void set_v(const double v)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
unsigned int getGrayLevelMin() const
void setComputeMoments(const bool activate)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void read(vpImage< unsigned char > &I, const std::string &filename)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getGrayLevelMax() const
void setGraphics(const bool activate)
void getEdges(std::list< vpImagePoint > &edges_list) const
static const vpColor blue