50 #include <visp/vpConfig.h>
51 #include <visp/vpDebug.h>
52 #include <visp/vpDisplayD3D.h>
53 #include <visp/vpDisplayGTK.h>
54 #include <visp/vpDisplayGDI.h>
55 #include <visp/vpDisplayOpenCV.h>
56 #include <visp/vpDisplayX.h>
57 #include <visp/vpHomogeneousMatrix.h>
58 #include <visp/vpImageIo.h>
59 #include <visp/vpIoTools.h>
60 #include <visp/vpMath.h>
61 #include <visp/vpMbEdgeTracker.h>
62 #include <visp/vpVideoReader.h>
63 #include <visp/vpParseArgv.h>
65 #if defined (VISP_HAVE_DISPLAY)
67 #define GETOPTARGS "x:m:i:n:dchtfCo"
69 void usage(
const char *name,
const char *badparam);
70 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
71 std::string &initFile,
bool &displayMovingEdge,
bool &click_allowed,
bool &display,
72 bool& cao3DModel,
bool& trackCylinder,
bool &useOgre);
74 void usage(
const char *name,
const char *badparam)
77 Example of tracking based on the 3D model.\n\
80 %s [-i <test image path>] [-x <config file>]\n\
81 [-m <model name>] [-n <initialisation file base name>]\n\
82 [-t] [-c] [-d] [-h] [-f] [-C]",
87 -i <input image path> \n\
88 Set image input path.\n\
89 From this path read images \n\
90 \"ViSP-images/mbt/cube/image%%04d.ppm\". These \n\
91 images come from ViSP-images-x.y.z.tar.gz available \n\
92 on the ViSP website.\n\
93 Setting the VISP_INPUT_IMAGE_PATH environment\n\
94 variable produces the same behaviour than using\n\
98 Set the config file (the xml file) to use.\n\
99 The config file is used to specify the parameters of the tracker.\n\
102 Specify the name of the file of the model\n\
103 The model can either be a vrml model (.wrl) or a .cao file.\n\
106 Do not use the vrml model, use the .cao one. These two models are \n\
107 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
108 website. However, the .cao model allows to use the 3d model based tracker \n\
112 Track only the cube (not the cylinder). In this case the models files are\n\
113 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
114 cube_and_cylinder.wrl.\n\
116 -n <initialisation file base name> \n\
117 Base name of the initialisation file. The file will be 'base_name'.init .\n\
118 This base name is also used for the optionnal picture specifying where to \n\
119 click (a .ppm picture).\
122 Turn off the display of the the moving edges. \n\
125 Turn off the display.\n\
128 Disable the mouse click. Useful to automaze the \n\
129 execution of this program without humain intervention.\n\
132 Use Ogre3D for visibility tests\n\
135 Print the help.\n\n");
138 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
142 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
143 std::string &initFile,
bool &displayMovingEdge,
bool &click_allowed,
bool &display,
144 bool& cao3DModel,
bool& trackCylinder,
bool &useOgre)
151 case 'i': ipath = optarg_;
break;
152 case 'x': configFile = optarg_;
break;
153 case 'm': modelFile = optarg_;
break;
154 case 'n': initFile = optarg_;
break;
155 case 't': displayMovingEdge =
false;
break;
156 case 'f': cao3DModel =
true;
break;
157 case 'c': click_allowed =
false;
break;
158 case 'd': display =
false;
break;
159 case 'C': trackCylinder =
false;
break;
160 case 'o' : useOgre =
true;
break;
161 case 'h': usage(argv[0], NULL);
return false;
break;
164 usage(argv[0], optarg_);
169 if ((c == 1) || (c == -1)) {
171 usage(argv[0], NULL);
172 std::cerr <<
"ERROR: " << std::endl;
173 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
181 main(
int argc,
const char ** argv)
184 std::string env_ipath;
185 std::string opt_ipath;
187 std::string opt_configFile;
188 std::string configFile;
189 std::string opt_modelFile;
190 std::string modelFile;
191 std::string opt_initFile;
192 std::string initFile;
193 bool displayMovingEdge =
true;
194 bool opt_click_allowed =
true;
195 bool opt_display =
true;
196 bool cao3DModel =
false;
197 bool trackCylinder =
true;
198 bool useOgre =
false;
201 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
206 if (! env_ipath.empty())
211 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayMovingEdge, opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre)) {
216 if (opt_ipath.empty() && env_ipath.empty() ){
217 usage(argv[0], NULL);
218 std::cerr << std::endl
219 <<
"ERROR:" << std::endl;
220 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
222 <<
" environment variable to specify the location of the " << std::endl
223 <<
" image path where test images are located." << std::endl
230 if (!opt_ipath.empty())
231 ipath = opt_ipath +
vpIoTools::path(
"/ViSP-images/mbt/cube/image%04d.pgm");
233 ipath = env_ipath +
vpIoTools::path(
"/ViSP-images/mbt/cube/image%04d.pgm");
235 if (!opt_configFile.empty())
236 configFile = opt_configFile;
237 else if (!opt_ipath.empty())
242 if (!opt_modelFile.empty()){
243 modelFile = opt_modelFile;
245 std::string modelFileCao;
246 std::string modelFileWrl;
248 modelFileCao =
"/ViSP-images/mbt/cube_and_cylinder.cao";
249 modelFileWrl =
"/ViSP-images/mbt/cube_and_cylinder.wrl";
251 modelFileCao =
"/ViSP-images/mbt/cube.cao";
252 modelFileWrl =
"/ViSP-images/mbt/cube.wrl";
255 if(!opt_ipath.empty()){
257 std::cout <<
"use cao" << std::endl;
261 #ifdef VISP_HAVE_COIN
262 std::cout <<
"use wrl" << std::endl;
265 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
272 std::cout <<
"use cao" << std::endl;
276 #ifdef VISP_HAVE_COIN
277 std::cout <<
"use wrl" << std::endl;
280 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
287 if (!opt_initFile.empty())
288 initFile = opt_initFile;
289 else if (!opt_ipath.empty())
301 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
308 #if defined VISP_HAVE_X11
310 #elif defined VISP_HAVE_GDI
312 #elif defined VISP_HAVE_OPENCV
314 #elif defined VISP_HAVE_D3D9
316 #elif defined VISP_HAVE_GTK
323 #if (defined VISP_HAVE_DISPLAY)
324 display.
init(I, 100, 100,
"Test tracking") ;
335 #if defined (VISP_HAVE_XML2)
372 if (opt_display && opt_click_allowed)
377 "click after positioning the object",
390 if (opt_display && opt_click_allowed)
392 tracker.
initClick(I, initFile.c_str(),
true);
399 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
413 while (!reader.
end())
438 #if defined (VISP_HAVE_XML2)
443 #ifdef VISP_HAVE_COIN
451 std::cout <<
"Catch an exception: " << e << std::endl;
460 std::cout <<
"Display is required to run this example." << std::endl;
void setDisplayMovingEdges(const bool displayMe)
void setMovingEdge(const vpMe &me)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void track(const vpImage< unsigned char > &I)
void setMaskNumber(const unsigned int &a)
static const vpColor darkRed
Display for windows using GDI (available on any windows 32 platform).
void setNbTotalSample(const int &nb)
Define the X11 console to display images.
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Contains predetermined masks for sites and holds moving edges tracking parameters.
Make the complete tracking of an object by using its CAD model.
virtual void setCameraParameters(const vpCameraParameters &camera)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
void loadConfigFile(const std::string &configFile)
static void flush(const vpImage< unsigned char > &I)
void setMu1(const double &mu_1)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
virtual void setNearClippingDistance(const double &dist)
void open(vpImage< vpRGBa > &I)
Display for windows using Direct3D.
void setMaskSize(const unsigned int &a)
void getPose(vpHomogeneousMatrix &cMo_) const
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void getCameraParameters(vpCameraParameters &camera) const
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void acquire(vpImage< vpRGBa > &I)
virtual void setFarClippingDistance(const double &dist)
void setFileName(const char *filename)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, const bool displayHelp=false)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness=1)
virtual void setOgreVisibilityTest(const bool &v)
void setMu2(const double &mu_2)
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
void setThreshold(const double &t)
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
virtual unsigned int getClipping() const
virtual bool getClick(bool blocking=true)=0
void loadModel(const std::string &cad_name)
void setRange(const unsigned int &r)
virtual void setClipping(const unsigned int &flags)
void setMinSampleStep(const double &min)
static const vpColor blue