62 #include <visp3/core/vpDebug.h>
63 #include <visp3/core/vpConfig.h>
68 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
70 #include <visp3/core/vpImage.h>
71 #include <visp3/io/vpImageIo.h>
72 #include <visp3/core/vpImagePoint.h>
74 #include <visp3/gui/vpDisplayX.h>
75 #include <visp3/gui/vpDisplayGTK.h>
76 #include <visp3/gui/vpDisplayGDI.h>
77 #include <visp3/gui/vpDisplayOpenCV.h>
79 #include <visp3/vision/vpPose.h>
80 #include <visp3/blob/vpDot.h>
81 #include <visp3/core/vpPixelMeterConversion.h>
82 #include <visp3/io/vpParseArgv.h>
83 #include <visp3/core/vpIoTools.h>
87 #define GETOPTARGS "cdi:p:hf:n:s:"
89 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
90 unsigned first,
unsigned nimages,
unsigned step);
91 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
92 unsigned &first,
unsigned &nimages,
unsigned &step,
93 bool &click_allowed,
bool &display);
108 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
109 unsigned first,
unsigned nimages,
unsigned step)
112 Test dot tracking.\n\
115 %s [-i <input image path>] [-p <personal image path>]\n\
116 [-f <first image>] [-n <number of images>] [-s <step>][-c] [-d] [-h]\n", name);
120 -i <input image path> %s\n\
121 Set image input path.\n\
122 From this path read images \n\
123 \"ViSP-images/cube/image.%%04d.pgm\"\n\
124 Setting the VISP_INPUT_IMAGE_PATH environment\n\
125 variable produces the same behaviour than using\n\
128 -p <personal image path> %s\n\
129 Specify a personal sequence containing images \n\
131 By image sequence, we mean one file per image.\n\
132 The following image file formats PNM (PGM P5, PPM P6)\n\
133 are supported. The format is selected by analysing \n\
134 the filename extension.\n\
135 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
136 %%04d is for the image numbering.\n\
138 -f <first image> %u\n\
139 First image number of the sequence.\n\
141 -n <number of images> %u\n\
142 Number of images to load from the sequence.\n\
145 Step between two images.\n\
148 Disable the mouse click. Useful to automaze the \n\
149 execution of this program without humain intervention.\n\
152 Turn off the display.\n\
156 ipath.c_str(),ppath.c_str(), first, nimages, step);
159 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
181 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
182 unsigned &first,
unsigned &nimages,
unsigned &step,
183 bool &click_allowed,
bool &display)
190 case 'c': click_allowed =
false;
break;
191 case 'd': display =
false;
break;
192 case 'i': ipath = optarg_;
break;
193 case 'p': ppath = optarg_;
break;
194 case 'f': first = (unsigned) atoi(optarg_);
break;
195 case 'n': nimages = (unsigned) atoi(optarg_);
break;
196 case 's': step = (unsigned) atoi(optarg_);
break;
197 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step);
return false;
break;
200 usage(argv[0], optarg_, ipath, ppath, first, nimages, step);
205 if ((c == 1) || (c == -1)) {
207 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
208 std::cerr <<
"ERROR: " << std::endl;
209 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
220 main(
int argc,
const char** argv)
223 std::string env_ipath;
224 std::string opt_ipath;
226 std::string opt_ppath;
228 std::string filename;
229 unsigned opt_first = 0;
230 unsigned opt_nimages = 80;
231 unsigned opt_step = 1;
232 bool opt_click_allowed =
true;
233 bool opt_display =
true;
237 std::cout <<
"-------------------------------------------------------" << std::endl ;
238 std::cout <<
" poseVirtualVS.cpp" <<std::endl << std::endl ;
240 std::cout <<
" Example of dots tracking in an image sequence and pose computation" << std::endl ;
241 std::cout <<
"-------------------------------------------------------" << std::endl ;
242 std::cout << std::endl ;
248 if (! env_ipath.empty())
252 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_click_allowed, opt_display) ==
false) {
257 if (!opt_ipath.empty())
262 if (opt_ipath.empty() && opt_ppath.empty()) {
263 if (ipath != env_ipath) {
264 std::cout << std::endl
265 <<
"WARNING: " << std::endl;
266 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
267 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
268 <<
" we skip the environment variable." << std::endl;
272 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()){
273 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
274 std::cerr << std::endl
275 <<
"ERROR:" << std::endl;
276 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
278 <<
" environment variable to specify the location of the " << std::endl
279 <<
" image path where test images are located." << std::endl
280 <<
" Use -p <personal image path> option if you want to "<< std::endl
281 <<
" use personal images" <<std::endl << std::endl;
293 unsigned iter = opt_first ;
294 std::ostringstream s;
295 char cfilename[FILENAME_MAX];
297 if (opt_ppath.empty()){
315 s.setf(std::ios::right, std::ios::adjustfield);
316 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
321 sprintf(cfilename, opt_ppath.c_str(), iter) ;
322 filename = cfilename;
328 for (i=0 ; i < 4 ; i++)
358 if (opt_ppath.empty()) {
359 std::cerr << std::endl
360 <<
"ERROR:" << std::endl;
361 std::cerr <<
" Cannot read " << filename << std::endl;
362 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
363 <<
" or VISP_INPUT_IMAGE_PATH environment variable"
367 std::cerr << std::endl
368 <<
"ERROR:" << std::endl;
369 std::cerr <<
" Cannot read " << filename << std::endl;
370 std::cerr <<
" or your -p " << opt_ppath <<
" option " <<std::endl
380 #if defined VISP_HAVE_X11
382 #elif defined VISP_HAVE_GTK
384 #elif defined VISP_HAVE_GDI
386 #elif defined VISP_HAVE_OPENCV
391 display.
init(I,100,100,
"tracking using vpDot");
403 if (opt_display && opt_click_allowed) {
405 std::cout <<
"Click the four white dots on the object corner clockwise"
407 for (i=0 ; i < 4 ; i++)
426 d[i].
track(I, cog[i]) ;
434 d[0].
track(I, cog[0]);
440 d[1].
track(I, cog[1]);
446 d[2].
track(I, cog[2]);
452 d[3].
track(I, cog[3]);
473 for (i=0 ; i < 4 ; i++)
515 for (i=0 ; i < 4 ; i++)
531 for (i=0 ; i < 4 ; i++)
556 while (iter < opt_nimages)
560 if (opt_ppath.empty()){
562 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
566 sprintf( cfilename, opt_ppath.c_str(), iter) ;
567 filename = cfilename ;
583 for (i=0 ; i < 4 ; i++)
586 d[i].
track(I, cog[i]) ;
628 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
636 vpERROR_TRACE(
"You do not have X11, GTK, GDI or OpenCV functionalities to display images...");
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
void track(const vpImage< unsigned char > &I)
error that can be emited by ViSP classes.
void set_x(const double x)
Set the point x coordinate in the image plane.
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that defines what is a point.
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
void set_u(const double u)
bool computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
compute the pose for a given method
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
void set_v(const double v)
Class used for pose computation from N points (pose from point only).
Generic class defining intrinsic camera parameters.
void set_y(const double y)
Set the point y coordinate in the image plane.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void setWorldCoordinates(const double oX, const double oY, const double oZ)
void setGraphics(const bool activate)
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static void read(vpImage< unsigned char > &I, const char *filename)
void addPoint(const vpPoint &P)
Add a new point in this array.
void initTracking(const vpImage< unsigned char > &I)
void clearPoint()
suppress all the point in the array of point