41 #include <visp3/core/vpConfig.h>
43 #if defined(VISP_HAVE_MODULE_BLOB) && defined(VISP_HAVE_DISPLAY)
45 #include <visp3/blob/vpDot2.h>
46 #include <visp3/core/vpImage.h>
47 #include <visp3/core/vpImagePoint.h>
48 #include <visp3/core/vpIoTools.h>
49 #include <visp3/gui/vpDisplayFactory.h>
50 #include <visp3/io/vpImageIo.h>
51 #include <visp3/io/vpParseArgv.h>
54 #define GETOPTARGS "cdf:i:l:p:s:h"
56 #ifdef ENABLE_VISP_NAMESPACE
71 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
72 unsigned last,
unsigned step)
74 #if VISP_HAVE_DATASET_VERSION >= 0x030600
75 std::string ext(
"png");
77 std::string ext(
"pgm");
80 Test dot tracking using vpDot2 class.\n\
83 %s [-i <test image path>] [-p <personal image path>]\n\
84 [-f <first image>] [-l <last image>] [-s <step>]\n\
90 -i <input image path> %s\n\
91 Set image input path.\n\
92 From this path read images \n\
93 \"mire-2/image.%%04d.%s\". These \n\
94 images come from visp-images-x.y.z.tar.gz available \n\
95 on the ViSP website.\n\
96 Setting the VISP_INPUT_IMAGE_PATH environment\n\
97 variable produces the same behaviour than using\n\
100 -p <personal image path> %s\n\
101 Specify a personal sequence containing images \n\
103 By image sequence, we mean one file per image.\n\
104 Example : \"C:/Temp/visp-images/cube/image.%%04d.%s\"\n\
105 %%04d is for the image numbering.\n\
107 -f <first image> %u\n\
108 First image number of the sequence.\n\
110 -l <last image> %u\n\
111 Last image number of the sequence.\n\
114 Step between two images.\n\
117 Disable the mouse click. Useful to automate the \n\
118 execution of this program without human intervention.\n\
121 Turn off the display.\n\
125 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
128 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
147 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
148 unsigned &step,
bool &click_allowed,
bool &display)
156 click_allowed =
false;
168 first = (unsigned)atoi(optarg_);
171 last = (unsigned)atoi(optarg_);
174 step = (unsigned)atoi(optarg_);
177 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
182 usage(argv[0], optarg_, ipath, ppath, first, last, step);
188 if ((c == 1) || (c == -1)) {
190 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
191 std::cerr <<
"ERROR: " << std::endl;
192 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
199 int main(
int argc,
const char **argv)
202 std::string env_ipath;
203 std::string opt_ipath;
205 std::string opt_ppath;
207 std::string filename;
208 unsigned opt_first = 1;
209 unsigned opt_last = 500;
210 unsigned opt_step = 1;
211 bool opt_click_allowed =
true;
212 bool opt_display =
true;
214 #if VISP_HAVE_DATASET_VERSION >= 0x030600
215 std::string ext(
"png");
217 std::string ext(
"pgm");
225 if (!env_ipath.empty())
229 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_click_allowed,
230 opt_display) ==
false) {
235 if (!opt_ipath.empty())
240 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
241 if (ipath != env_ipath) {
242 std::cout << std::endl <<
"WARNING: " << std::endl;
243 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
244 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
245 <<
" we skip the environment variable." << std::endl;
250 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
251 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
252 std::cerr << std::endl <<
"ERROR:" << std::endl;
253 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
254 <<
" environment variable to specify the location of the " << std::endl
255 <<
" image path where test images are located." << std::endl
256 <<
" Use -p <personal image path> option if you want to " << std::endl
257 <<
" use personal images." << std::endl
269 unsigned iter = opt_first;
270 std::ostringstream s;
271 char cfilename[FILENAME_MAX];
273 if (opt_ppath.empty()) {
288 s.setf(std::ios::right, std::ios::adjustfield);
289 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
293 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
294 filename = cfilename;
303 std::cout <<
"Load: " << filename << std::endl;
309 std::cerr << std::endl <<
"ERROR:" << std::endl;
310 std::cerr <<
" Cannot read " << filename << std::endl;
311 if (opt_ppath.empty()) {
312 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
313 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
316 std::cerr <<
" Check your -p " << opt_ppath <<
" option " << std::endl;
325 display->init(I, 100, 100,
"Display...");
368 if (opt_display && opt_click_allowed) {
369 std::cout <<
"Click on a dot to track it." << std::endl;
379 std::cout <<
"COG: " << std::endl;
381 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v() << std::endl;
382 std::cout <<
"Size:" << std::endl;
384 std::cout <<
"Area: " << d.
getArea() << std::endl;
385 std::cout <<
"Centered normalized moments nij:" << std::endl;
386 std::cout <<
" n20: " << d.
get_nij()[0] << std::endl;
387 std::cout <<
" n11: " << d.
get_nij()[1] << std::endl;
388 std::cout <<
" n02: " << d.
get_nij()[2] << std::endl;
389 std::cout <<
"Settings:" << std::endl;
397 while ((iter < opt_last) && (!quit)) {
399 if (opt_ppath.empty()) {
401 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
405 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
406 filename = cfilename;
409 std::cout <<
"read : " << filename << std::endl;
423 std::cout <<
"Tracking on image: " << filename << std::endl;
429 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v() << std::endl;
430 std::cout <<
"Size:" << std::endl;
432 std::cout <<
"Area: " << d.
getArea() << std::endl;
433 std::cout <<
"Centered normalized moments nij:" << std::endl;
434 std::cout <<
" n20: " << d.
get_nij()[0] << std::endl;
435 std::cout <<
" n11: " << d.
get_nij()[1] << std::endl;
436 std::cout <<
" n02: " << d.
get_nij()[2] << std::endl;
437 std::cout <<
"Settings:" << std::endl;
445 std::list<vpImagePoint> edges;
447 std::list<vpImagePoint>::const_iterator it;
448 for (it = edges.begin(); it != edges.end(); ++it) {
465 if (opt_display && opt_click_allowed && !quit) {
466 std::cout <<
"\nA click to exit..." << std::endl;
476 std::cout <<
"Catch an exception: " << e << std::endl;
485 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display "
486 "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 displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
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 track(const vpImage< unsigned char > &I, bool canMakeTheWindowGrow=true)
void setGraphics(bool activate)
void getEdges(std::list< vpImagePoint > &edges_list) const
void setGrayLevelPrecision(const double &grayLevelPrecision)
vpImagePoint getCog() const
double getSizePrecision() const
double getGrayLevelPrecision() const
void setComputeMoments(bool activate)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
vpColVector get_nij() const
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)
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()