48 #include <visp3/core/vpConfig.h>
49 #include <visp3/core/vpDebug.h>
56 #if defined(VISP_HAVE_MODULE_BLOB) && \
57 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
59 #include <visp3/blob/vpDot.h>
60 #include <visp3/core/vpImage.h>
61 #include <visp3/core/vpImagePoint.h>
62 #include <visp3/core/vpIoTools.h>
63 #include <visp3/gui/vpDisplayGDI.h>
64 #include <visp3/gui/vpDisplayGTK.h>
65 #include <visp3/gui/vpDisplayOpenCV.h>
66 #include <visp3/gui/vpDisplayX.h>
67 #include <visp3/io/vpImageIo.h>
68 #include <visp3/io/vpParseArgv.h>
71 #define GETOPTARGS "cdf:hi:l:p:s:"
73 #ifdef ENABLE_VISP_NAMESPACE
90 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
91 unsigned last,
unsigned step)
93 #if VISP_HAVE_DATASET_VERSION >= 0x030600
94 std::string ext(
"png");
96 std::string ext(
"pgm");
102 %s [-i <test image path>] [-p <personal image path>]\n\
103 [-f <first image>] [-l <last image>] [-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.%s\". 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 Example : \"C:/Temp/visp-images/cube/image.%%04d.%s\"\n\
123 %%04d is for the image numbering.\n\
125 -f <first image> %u\n\
126 First image number of the sequence.\n\
128 -l <last image> %u\n\
129 Last image number of the sequence.\n\
132 Step between two images.\n\
135 Disable the mouse click. Useful to automate the \n\
136 execution of this program without human intervention.\n\
139 Turn off the display.\n\
143 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
146 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
165 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
166 unsigned &step,
bool &click_allowed,
bool &display)
174 click_allowed =
false;
186 first = (unsigned)atoi(optarg_);
189 last = (unsigned)atoi(optarg_);
192 step = (unsigned)atoi(optarg_);
195 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
200 usage(argv[0], optarg_, ipath, ppath, first, last, step);
206 if ((c == 1) || (c == -1)) {
208 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
209 std::cerr <<
"ERROR: " << std::endl;
210 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
217 int main(
int argc,
const char **argv)
220 std::string env_ipath;
221 std::string opt_ipath;
223 std::string opt_ppath;
225 std::string filename;
226 unsigned int opt_first = 1;
227 unsigned int opt_last = 500;
228 unsigned int opt_step = 1;
229 bool opt_click_allowed =
true;
230 bool opt_display =
true;
232 #if VISP_HAVE_DATASET_VERSION >= 0x030600
233 std::string ext(
"png");
235 std::string ext(
"pgm");
243 if (!env_ipath.empty())
247 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_click_allowed,
248 opt_display) ==
false) {
253 if (!opt_ipath.empty())
258 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
259 if (ipath != env_ipath) {
260 std::cout << std::endl <<
"WARNING: " << std::endl;
261 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
262 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
263 <<
" we skip the environment variable." << std::endl;
268 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
269 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
270 std::cerr << std::endl <<
"ERROR:" << std::endl;
271 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
272 <<
" environment variable to specify the location of the " << std::endl
273 <<
" image path where test images are located." << std::endl
274 <<
" Use -p <personal image path> option if you want to " << std::endl
275 <<
" use personal images." << std::endl
286 unsigned iter = opt_first;
287 std::ostringstream s;
288 char cfilename[FILENAME_MAX];
290 if (opt_ppath.empty()) {
304 s.setf(std::ios::right, std::ios::adjustfield);
305 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
309 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
310 filename = cfilename;
319 vpCTRACE <<
"Load: " << filename << std::endl;
325 std::cerr << std::endl <<
"ERROR:" << std::endl;
326 std::cerr <<
" Cannot read " << filename << std::endl;
327 if (opt_ppath.empty()) {
328 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
329 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
332 std::cerr <<
" Check your -p " << opt_ppath <<
" option " << std::endl;
338 #if defined(VISP_HAVE_X11)
340 #elif defined(VISP_HAVE_GTK)
342 #elif defined(VISP_HAVE_GDI)
344 #elif defined(HAVE_OPENCV_HIGHGUI)
350 display.init(I, 100, 100,
"Display...");
370 d.setGraphics(
false);
373 d.setComputeMoments(
true);
376 if (opt_display && opt_click_allowed) {
380 std::cout <<
"Click on a white dot you want to track..." << std::endl;
390 d.initTracking(I, ip);
394 while (iter < opt_last) {
396 if (opt_ppath.empty()) {
398 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
402 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
403 filename = cfilename;
406 std::cout <<
"read: " << filename << std::endl;
413 std::cout <<
"Tracking on image: " << filename << std::endl;
421 std::cout << cog.
get_u() <<
" " << cog.
get_v() << std::endl;
422 std::cout <<
"Size:" << std::endl;
424 std::cout <<
"Area: " << d.getArea() << std::endl;
425 std::cout <<
"Centered normalized moments nij:" << std::endl;
426 std::cout <<
" n20: " << d.get_nij()[0] << std::endl;
427 std::cout <<
" n11: " << d.get_nij()[1] << std::endl;
428 std::cout <<
" n02: " << d.get_nij()[2] << std::endl;
431 std::list<vpImagePoint> edges = d.getEdges();
432 std::list<vpImagePoint>::const_iterator it;
433 for (it = edges.begin(); it != edges.end(); ++it) {
448 if (opt_display && opt_click_allowed) {
449 std::cout <<
"\nA click to exit..." << std::endl;
456 std::cout <<
"Catch an exception: " << e << std::endl;
465 std::cout <<
"visp_blob module or X11, GTK, GDI or OpenCV display "
466 "functionalities are required..."
static const vpColor blue
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...
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 dot (connected 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)
VISP_EXPORT double measureTimeMs()