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
60void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath,
unsigned first,
61 unsigned last,
unsigned step);
62bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
63 unsigned &step,
bool &click_allowed,
bool &display);
76void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath,
unsigned first,
77 unsigned last,
unsigned step)
79#if defined(VISP_HAVE_DATASET)
80#if VISP_HAVE_DATASET_VERSION >= 0x030600
81 std::string ext(
"png");
83 std::string ext(
"pgm");
87 std::string ext(
"png");
90Test dot tracking using vpDot2 class.\n\
93 %s [-i <test image path>] [-p <personal image path>]\n\
94 [-f <first image>] [-l <last image>] [-s <step>]\n\
100 -i <input image path> %s\n\
101 Set image input path.\n\
102 From this path read images \n\
103 \"mire-2/image.%%04d.%s\". These \n\
104 images come from visp-images-x.y.z.tar.gz available \n\
105 on the ViSP website.\n\
106 Setting the VISP_INPUT_IMAGE_PATH environment\n\
107 variable produces the same behaviour than using\n\
110 -p <personal image path> %s\n\
111 Specify a personal sequence containing images \n\
113 By image sequence, we mean one file per image.\n\
114 Example : \"C:/Temp/visp-images/cube/image.%%04d.%s\"\n\
115 %%04d is for the image numbering.\n\
117 -f <first image> %u\n\
118 First image number of the sequence.\n\
120 -l <last image> %u\n\
121 Last image number of the sequence.\n\
124 Step between two images.\n\
127 Disable the mouse click. Useful to automate the \n\
128 execution of this program without human intervention.\n\
131 Turn off the display.\n\
135 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
138 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
156bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
157 unsigned &step,
bool &click_allowed,
bool &display)
165 click_allowed =
false;
177 first =
static_cast<unsigned int>(atoi(optarg_));
180 last =
static_cast<unsigned int>(atoi(optarg_));
183 step =
static_cast<unsigned int>(atoi(optarg_));
186 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
190 usage(argv[0], optarg_, ipath, ppath, first, last, step);
195 if ((c == 1) || (c == -1)) {
197 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
198 std::cerr <<
"ERROR: " << std::endl;
199 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
206int main(
int argc,
const char **argv)
209 std::string env_ipath;
210 std::string opt_ipath;
212 std::string opt_ppath;
215 unsigned opt_first = 1;
216 unsigned opt_last = 500;
217 unsigned opt_step = 1;
218 bool opt_click_allowed =
true;
219 bool opt_display =
true;
221#if defined(VISP_HAVE_DATASET)
222#if VISP_HAVE_DATASET_VERSION >= 0x030600
223 std::string ext(
"png");
225 std::string ext(
"pgm");
229 std::string ext(
"png");
237 if (!env_ipath.empty())
241 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_click_allowed,
242 opt_display) ==
false) {
247 if (!opt_ipath.empty())
252 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
253 if (ipath != env_ipath) {
254 std::cout << std::endl <<
"WARNING: " << std::endl;
255 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
256 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
257 <<
" we skip the environment variable." << std::endl;
262 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
263 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
264 std::cerr << std::endl <<
"ERROR:" << std::endl;
265 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
266 <<
" environment variable to specify the location of the " << std::endl
267 <<
" image path where test images are located." << std::endl
268 <<
" Use -p <personal image path> option if you want to " << std::endl
269 <<
" use personal images." << std::endl
281 unsigned iter = opt_first;
283 if (opt_ppath.empty()) {
310 std::cout <<
"Load: " <<
filename << std::endl;
316 std::cerr << std::endl <<
"ERROR:" << std::endl;
317 std::cerr <<
" Cannot read " <<
filename << std::endl;
318 if (opt_ppath.empty()) {
319 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
320 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
323 std::cerr <<
" Check your -p " << opt_ppath <<
" option " << std::endl;
332 display->init(I, 100, 100,
"Display...");
361 d.setGraphics(
false);
366 d.setComputeMoments(
true);
367 d.setGrayLevelPrecision(0.90);
375 if (opt_display && opt_click_allowed) {
376 std::cout <<
"Click on a dot to track it." << std::endl;
383 d.initTracking(I, ip);
386 std::cout <<
"COG: " << std::endl;
388 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v() << std::endl;
389 std::cout <<
"Size:" << std::endl;
390 std::cout <<
" w: " <<
d.getWidth() <<
" h: " <<
d.getHeight() << std::endl;
391 std::cout <<
"Area: " <<
d.getArea() << std::endl;
392 std::cout <<
"Centered normalized moments nij:" << std::endl;
393 std::cout <<
" n20: " <<
d.get_nij()[0] << std::endl;
394 std::cout <<
" n11: " <<
d.get_nij()[1] << std::endl;
395 std::cout <<
" n02: " <<
d.get_nij()[2] << std::endl;
396 std::cout <<
"Settings:" << std::endl;
397 std::cout <<
" gray level min: " <<
d.getGrayLevelMin() << std::endl;
398 std::cout <<
" gray level max: " <<
d.getGrayLevelMax() << std::endl;
399 std::cout <<
" size precision: " <<
d.getSizePrecision() << std::endl;
400 std::cout <<
" gray level precision: " <<
d.getGrayLevelPrecision() << std::endl;
404 while ((iter < opt_last) && (!quit)) {
406 if (opt_ppath.empty()) {
414 std::cout <<
"read : " <<
filename << std::endl;
428 std::cout <<
"Tracking on image: " <<
filename << std::endl;
434 std::cout <<
" u: " << cog.
get_u() <<
" v: " << cog.
get_v() << std::endl;
435 std::cout <<
"Size:" << std::endl;
436 std::cout <<
" w: " <<
d.getWidth() <<
" h: " <<
d.getHeight() << std::endl;
437 std::cout <<
"Area: " <<
d.getArea() << std::endl;
438 std::cout <<
"Centered normalized moments nij:" << std::endl;
439 std::cout <<
" n20: " <<
d.get_nij()[0] << std::endl;
440 std::cout <<
" n11: " <<
d.get_nij()[1] << std::endl;
441 std::cout <<
" n02: " <<
d.get_nij()[2] << std::endl;
442 std::cout <<
"Settings:" << std::endl;
443 std::cout <<
" gray level min: " <<
d.getGrayLevelMin() << std::endl;
444 std::cout <<
" gray level max: " <<
d.getGrayLevelMax() << std::endl;
445 std::cout <<
" size precision: " <<
d.getSizePrecision() << std::endl;
446 std::cout <<
" gray level precision: " <<
d.getGrayLevelPrecision() << std::endl;
450 std::list<vpImagePoint> edges;
452 std::list<vpImagePoint>::const_iterator it;
453 for (it = edges.begin(); it != edges.end(); ++it) {
470 if (opt_display && opt_click_allowed && !quit) {
471 std::cout <<
"\nA click to exit..." << std::endl;
481 std::cout <<
"Catch an exception: " <<
e << std::endl;
490 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display "
491 "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.
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.
VISP_EXPORT double measureTimeMs()