46 #include <visp3/core/vpConfig.h>
48 #if defined(VISP_HAVE_MODULE_BLOB) && defined(VISP_HAVE_DISPLAY)
50 #include <visp3/blob/vpDot.h>
51 #include <visp3/core/vpImage.h>
52 #include <visp3/core/vpImagePoint.h>
53 #include <visp3/core/vpIoTools.h>
54 #include <visp3/gui/vpDisplayFactory.h>
55 #include <visp3/io/vpImageIo.h>
56 #include <visp3/io/vpParseArgv.h>
59 #define GETOPTARGS "cdf:hi:l:p:s:"
61 #ifdef ENABLE_VISP_NAMESPACE
78 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
79 unsigned last,
unsigned step)
81 #if VISP_HAVE_DATASET_VERSION >= 0x030600
82 std::string ext(
"png");
84 std::string ext(
"pgm");
90 %s [-i <test image path>] [-p <personal image path>]\n\
91 [-f <first image>] [-l <last image>] [-s <step>]\n\
92 [-c] [-d] [-h]\n", name);
96 -i <input image path> %s\n\
97 Set image input path.\n\
98 From this path read images \n\
99 \"mire-2/image.%%04d.%s\". These \n\
100 images come from visp-images-x.y.z.tar.gz available \n\
101 on the ViSP website.\n\
102 Setting the VISP_INPUT_IMAGE_PATH environment\n\
103 variable produces the same behaviour than using\n\
106 -p <personal image path> %s\n\
107 Specify a personal sequence containing images \n\
109 By image sequence, we mean one file per image.\n\
110 Example : \"C:/Temp/visp-images/cube/image.%%04d.%s\"\n\
111 %%04d is for the image numbering.\n\
113 -f <first image> %u\n\
114 First image number of the sequence.\n\
116 -l <last image> %u\n\
117 Last image number of the sequence.\n\
120 Step between two images.\n\
123 Disable the mouse click. Useful to automate the \n\
124 execution of this program without human intervention.\n\
127 Turn off the display.\n\
131 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
134 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
153 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
154 unsigned &step,
bool &click_allowed,
bool &display)
162 click_allowed =
false;
174 first = (unsigned)atoi(optarg_);
177 last = (unsigned)atoi(optarg_);
180 step = (unsigned)atoi(optarg_);
183 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
188 usage(argv[0], optarg_, ipath, ppath, first, last, step);
194 if ((c == 1) || (c == -1)) {
196 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
197 std::cerr <<
"ERROR: " << std::endl;
198 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
205 int main(
int argc,
const char **argv)
208 std::string env_ipath;
209 std::string opt_ipath;
211 std::string opt_ppath;
213 std::string filename;
214 unsigned int opt_first = 1;
215 unsigned int opt_last = 500;
216 unsigned int opt_step = 1;
217 bool opt_click_allowed =
true;
218 bool opt_display =
true;
220 #if VISP_HAVE_DATASET_VERSION >= 0x030600
221 std::string ext(
"png");
223 std::string ext(
"pgm");
231 if (!env_ipath.empty())
235 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_click_allowed,
236 opt_display) ==
false) {
241 if (!opt_ipath.empty())
246 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
247 if (ipath != env_ipath) {
248 std::cout << std::endl <<
"WARNING: " << std::endl;
249 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
250 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
251 <<
" we skip the environment variable." << std::endl;
256 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
257 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
258 std::cerr << std::endl <<
"ERROR:" << std::endl;
259 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
260 <<
" environment variable to specify the location of the " << std::endl
261 <<
" image path where test images are located." << std::endl
262 <<
" Use -p <personal image path> option if you want to " << std::endl
263 <<
" use personal images." << std::endl
275 unsigned iter = opt_first;
276 std::ostringstream s;
277 char cfilename[FILENAME_MAX];
279 if (opt_ppath.empty()) {
293 s.setf(std::ios::right, std::ios::adjustfield);
294 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
298 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
299 filename = cfilename;
308 std::cout <<
"Load: " << filename << std::endl;
314 std::cerr << std::endl <<
"ERROR:" << std::endl;
315 std::cerr <<
" Cannot read " << filename << std::endl;
316 if (opt_ppath.empty()) {
317 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
318 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
321 std::cerr <<
" Check your -p " << opt_ppath <<
" option " << std::endl;
330 display->init(I, 100, 100,
"Display...");
356 if (opt_display && opt_click_allowed) {
360 std::cout <<
"Click on a white dot you want to track..." << std::endl;
374 while ((iter < opt_last) && (!quit)) {
376 if (opt_ppath.empty()) {
378 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
382 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
383 filename = cfilename;
386 std::cout <<
"read: " << filename << std::endl;
393 std::cout <<
"Tracking on image: " << filename << std::endl;
401 std::cout << cog.
get_u() <<
" " << cog.
get_v() << std::endl;
402 std::cout <<
"Size:" << std::endl;
404 std::cout <<
"Area: " << d.
getArea() << std::endl;
405 std::cout <<
"Centered normalized moments nij:" << std::endl;
406 std::cout <<
" n20: " << d.
get_nij()[0] << std::endl;
407 std::cout <<
" n11: " << d.
get_nij()[1] << std::endl;
408 std::cout <<
" n02: " << d.
get_nij()[2] << std::endl;
411 std::list<vpImagePoint> edges = d.
getEdges();
412 std::list<vpImagePoint>::const_iterator it;
413 for (it = edges.begin(); it != edges.end(); ++it) {
433 if (opt_display && opt_click_allowed && !quit) {
434 std::cout <<
"\nA click to exit..." << std::endl;
444 std::cout <<
"Catch an exception: " << e << std::endl;
453 std::cout <<
"visp_blob module or X11, GTK, GDI or OpenCV display "
454 "functionalities are required..."
static const vpColor blue
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 dot (connected pixels with same gray level) on a vpImage.
unsigned int getWidth() const
void initTracking(const vpImage< unsigned char > &I)
void setGraphics(bool activate)
void setConnexity(const vpConnexityType &connexityType)
std::list< vpImagePoint > getEdges() const
void setComputeMoments(bool activate)
vpColVector get_nij() const
vpImagePoint getCog() const
void track(const vpImage< unsigned char > &I)
unsigned int getHeight() 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()