66 #include <visp/vpDebug.h>
67 #include <visp/vpConfig.h>
72 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
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>
81 #include <visp/vpDisplayOpenCV.h>
83 #include <visp/vpPose.h>
84 #include <visp/vpDot.h>
85 #include <visp/vpPixelMeterConversion.h>
86 #include <visp/vpParseArgv.h>
87 #include <visp/vpIoTools.h>
91 #define GETOPTARGS "cdi:p:hf:n:s:"
93 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
94 unsigned first,
unsigned nimages,
unsigned step);
95 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
96 unsigned &first,
unsigned &nimages,
unsigned &step,
97 bool &click_allowed,
bool &display);
112 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
113 unsigned first,
unsigned nimages,
unsigned step)
116 Test dot tracking.\n\
119 %s [-i <input image path>] [-p <personal image path>]\n\
120 [-f <first image>] [-n <number of images>] [-s <step>][-c] [-d] [-h]\n", name);
124 -i <input image path> %s\n\
125 Set image input path.\n\
126 From this path read images \n\
127 \"ViSP-images/cube/image.%%04d.pgm\"\n\
128 Setting the VISP_INPUT_IMAGE_PATH environment\n\
129 variable produces the same behaviour than using\n\
132 -p <personal image path> %s\n\
133 Specify a personal sequence containing images \n\
135 By image sequence, we mean one file per image.\n\
136 The following image file formats PNM (PGM P5, PPM P6)\n\
137 are supported. The format is selected by analysing \n\
138 the filename extension.\n\
139 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
140 %%04d is for the image numbering.\n\
142 -f <first image> %u\n\
143 First image number of the sequence.\n\
145 -n <number of images> %u\n\
146 Number of images to load from the sequence.\n\
149 Step between two images.\n\
152 Disable the mouse click. Useful to automaze the \n\
153 execution of this program without humain intervention.\n\
156 Turn off the display.\n\
160 ipath.c_str(),ppath.c_str(), first, nimages, step);
163 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
185 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
186 unsigned &first,
unsigned &nimages,
unsigned &step,
187 bool &click_allowed,
bool &display)
194 case 'c': click_allowed =
false;
break;
195 case 'd': display =
false;
break;
196 case 'i': ipath = optarg_;
break;
197 case 'p': ppath = optarg_;
break;
198 case 'f': first = (unsigned) atoi(optarg_);
break;
199 case 'n': nimages = (unsigned) atoi(optarg_);
break;
200 case 's': step = (unsigned) atoi(optarg_);
break;
201 case 'h': usage(argv[0], NULL, ipath, ppath, first, nimages, step);
return false;
break;
204 usage(argv[0], optarg_, ipath, ppath, first, nimages, step);
209 if ((c == 1) || (c == -1)) {
211 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
212 std::cerr <<
"ERROR: " << std::endl;
213 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
224 main(
int argc,
const char** argv)
227 std::string env_ipath;
228 std::string opt_ipath;
230 std::string opt_ppath;
232 std::string filename;
233 unsigned opt_first = 0;
234 unsigned opt_nimages = 80;
235 unsigned opt_step = 1;
236 bool opt_click_allowed =
true;
237 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 ;
252 if (! env_ipath.empty())
256 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_click_allowed, opt_display) ==
false) {
261 if (!opt_ipath.empty())
266 if (opt_ipath.empty() && opt_ppath.empty()) {
267 if (ipath != env_ipath) {
268 std::cout << std::endl
269 <<
"WARNING: " << std::endl;
270 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
271 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
272 <<
" we skip the environment variable." << std::endl;
276 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()){
277 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
278 std::cerr << std::endl
279 <<
"ERROR:" << std::endl;
280 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
282 <<
" environment variable to specify the location of the " << std::endl
283 <<
" image path where test images are located." << std::endl
284 <<
" Use -p <personal image path> option if you want to "<< std::endl
285 <<
" use personal images" <<std::endl << std::endl;
297 unsigned iter = opt_first ;
298 std::ostringstream s;
299 char cfilename[FILENAME_MAX];
301 if (opt_ppath.empty()){
319 s.setf(std::ios::right, std::ios::adjustfield);
320 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
325 sprintf(cfilename, opt_ppath.c_str(), iter) ;
326 filename = cfilename;
332 for (i=0 ; i < 4 ; i++)
362 if (opt_ppath.empty()) {
363 std::cerr << std::endl
364 <<
"ERROR:" << std::endl;
365 std::cerr <<
" Cannot read " << filename << std::endl;
366 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
367 <<
" or VISP_INPUT_IMAGE_PATH environment variable"
371 std::cerr << std::endl
372 <<
"ERROR:" << std::endl;
373 std::cerr <<
" Cannot read " << filename << std::endl;
374 std::cerr <<
" or your -p " << opt_ppath <<
" option " <<std::endl
384 #if defined VISP_HAVE_X11
386 #elif defined VISP_HAVE_GTK
388 #elif defined VISP_HAVE_GDI
390 #elif defined VISP_HAVE_OPENCV
395 display.
init(I,100,100,
"tracking using vpDot");
407 if (opt_display && opt_click_allowed) {
409 std::cout <<
"Click the four white dots on the object corner clockwise"
411 for (i=0 ; i < 4 ; i++)
430 d[i].
track(I, cog[i]) ;
438 d[0].
track(I, cog[0]);
444 d[1].
track(I, cog[1]);
450 d[2].
track(I, cog[2]);
456 d[3].
track(I, cog[3]);
477 for (i=0 ; i < 4 ; i++)
519 for (i=0 ; i < 4 ; i++)
535 for (i=0 ; i < 4 ; i++)
560 while (iter < opt_nimages)
564 if (opt_ppath.empty()){
566 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
570 sprintf( cfilename, opt_ppath.c_str(), iter) ;
571 filename = cfilename ;
587 for (i=0 ; i < 4 ; i++)
590 d[i].
track(I, cog[i]) ;
632 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
640 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)
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)
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 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 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