66 #include <visp/vpDebug.h>
67 #include <visp/vpConfig.h>
72 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
74 #include <visp/vpImage.h>
75 #include <visp/vpImageIo.h>
76 #include <visp/vpImagePoint.h>
78 #include <visp/vpDisplayX.h>
79 #include <visp/vpDisplayGTK.h>
80 #include <visp/vpDisplayGDI.h>
82 #include <visp/vpPose.h>
83 #include <visp/vpDot.h>
84 #include <visp/vpPixelMeterConversion.h>
85 #include <visp/vpParseArgv.h>
86 #include <visp/vpIoTools.h>
90 #define GETOPTARGS "cdi:p:hf:n:s:"
92 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
93 unsigned first,
unsigned nimages,
unsigned step);
94 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
95 unsigned &first,
unsigned &nimages,
unsigned &step,
96 bool &click_allowed,
bool &display);
111 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
112 unsigned first,
unsigned nimages,
unsigned step)
115 Test dot tracking.\n\
118 %s [-i <input image path>] [-p <personal image path>]\n\
119 [-f <first image>] [-n <number of images>] [-s <step>][-c] [-d] [-h]\n", name);
123 -i <input image path> %s\n\
124 Set image input path.\n\
125 From this path read images \n\
126 \"ViSP-images/cube/image.%%04d.pgm\"\n\
127 Setting the VISP_INPUT_IMAGE_PATH environment\n\
128 variable produces the same behaviour than using\n\
131 -p <personal image path> %s\n\
132 Specify a personal sequence containing images \n\
134 By image sequence, we mean one file per image.\n\
135 The following image file formats PNM (PGM P5, PPM P6)\n\
136 are supported. The format is selected by analysing \n\
137 the filename extension.\n\
138 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
139 %%04d is for the image numbering.\n\
141 -f <first image> %u\n\
142 First image number of the sequence.\n\
144 -n <number of images> %u\n\
145 Number of images to load from the sequence.\n\
148 Step between two images.\n\
151 Disable the mouse click. Useful to automaze the \n\
152 execution of this program without humain intervention.\n\
155 Turn off the display.\n\
159 ipath.c_str(),ppath.c_str(), first, nimages, step);
162 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
184 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
185 unsigned &first,
unsigned &nimages,
unsigned &step,
186 bool &click_allowed,
bool &display)
193 case 'c': click_allowed =
false;
break;
194 case 'd': display =
false;
break;
195 case 'i': ipath = optarg_;
break;
196 case 'p': ppath = optarg_;
break;
197 case 'f': first = (unsigned) atoi(optarg_);
break;
198 case 'n': nimages = (unsigned) atoi(optarg_);
break;
199 case 's': step = (unsigned) atoi(optarg_);
break;
200 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step);
return false;
break;
203 usage(argv[0], optarg_, ipath, ppath, first, nimages, step);
208 if ((c == 1) || (c == -1)) {
210 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
211 std::cerr <<
"ERROR: " << std::endl;
212 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
223 main(
int argc,
const char** argv)
226 std::string env_ipath;
227 std::string opt_ipath;
229 std::string opt_ppath;
231 std::string filename;
232 unsigned opt_first = 0;
233 unsigned opt_nimages = 80;
234 unsigned opt_step = 1;
235 bool opt_click_allowed =
true;
236 bool opt_display =
true;
241 std::cout <<
"-------------------------------------------------------" << std::endl ;
242 std::cout <<
" poseVirtualVS.cpp" <<std::endl << std::endl ;
244 std::cout <<
" Example of dots tracking in an image sequence and pose computation" << std::endl ;
245 std::cout <<
"-------------------------------------------------------" << std::endl ;
246 std::cout << std::endl ;
249 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
254 if (! env_ipath.empty())
259 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_click_allowed, opt_display) ==
false) {
264 if (!opt_ipath.empty())
269 if (opt_ipath.empty() && opt_ppath.empty()) {
270 if (ipath != env_ipath) {
271 std::cout << std::endl
272 <<
"WARNING: " << std::endl;
273 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
274 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
275 <<
" we skip the environment variable." << std::endl;
279 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()){
280 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
281 std::cerr << std::endl
282 <<
"ERROR:" << std::endl;
283 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
285 <<
" environment variable to specify the location of the " << std::endl
286 <<
" image path where test images are located." << std::endl
287 <<
" Use -p <personal image path> option if you want to "<< std::endl
288 <<
" use personal images" <<std::endl << std::endl;
300 unsigned iter = opt_first ;
301 std::ostringstream s;
302 char cfilename[FILENAME_MAX];
304 if (opt_ppath.empty()){
323 s.setf(std::ios::right, std::ios::adjustfield);
324 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
325 filename = dirname + s.str();
329 sprintf(cfilename, opt_ppath.c_str(), iter) ;
330 filename = cfilename;
336 for (i=0 ; i < 4 ; i++)
366 if (opt_ppath.empty()) {
367 std::cerr << std::endl
368 <<
"ERROR:" << std::endl;
369 std::cerr <<
" Cannot read " << filename << std::endl;
370 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
371 <<
" or VISP_INPUT_IMAGE_PATH environment variable"
375 std::cerr << std::endl
376 <<
"ERROR:" << std::endl;
377 std::cerr <<
" Cannot read " << filename << std::endl;
378 std::cerr <<
" or your -p " << opt_ppath <<
" option " <<std::endl
388 #if defined VISP_HAVE_X11
390 #elif defined VISP_HAVE_GTK
392 #elif defined VISP_HAVE_GDI
397 display.
init(I,100,100,
"tracking using vpDot");
409 if (opt_display && opt_click_allowed) {
411 std::cout <<
"Click the four white dots on the object corner clockwise"
413 for (i=0 ; i < 4 ; i++)
432 d[i].
track(I, cog[i]) ;
440 d[0].
track(I, cog[0]);
446 d[1].
track(I, cog[1]);
452 d[2].
track(I, cog[2]);
458 d[3].
track(I, cog[3]);
479 for (i=0 ; i < 4 ; i++)
521 for (i=0 ; i < 4 ; i++)
537 for (i=0 ; i < 4 ; i++)
562 while (iter < opt_nimages)
566 if (opt_ppath.empty()){
568 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
569 filename = dirname + s.str();
572 sprintf( cfilename, opt_ppath.c_str(), iter) ;
573 filename = cfilename ;
589 for (i=0 ; i < 4 ; i++)
592 d[i].
track(I, cog[i]) ;
634 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
642 vpERROR_TRACE(
"You do not have X11 or GTK functionalities to display images...");
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
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)
static void display(const vpImage< unsigned char > &I)
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 init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void setGraphics(const bool activate)
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
void computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo)
compute the pose for a given method
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 setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
void clearPoint()
suppress all the point in the array of point