47 #include <visp3/core/vpConfig.h>
49 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY)
51 #include <visp3/core/vpDebug.h>
52 #include <visp3/gui/vpDisplayD3D.h>
53 #include <visp3/gui/vpDisplayGTK.h>
54 #include <visp3/gui/vpDisplayGDI.h>
55 #include <visp3/gui/vpDisplayOpenCV.h>
56 #include <visp3/gui/vpDisplayX.h>
57 #include <visp3/core/vpHomogeneousMatrix.h>
58 #include <visp3/io/vpImageIo.h>
59 #include <visp3/core/vpIoTools.h>
60 #include <visp3/core/vpMath.h>
61 #include <visp3/io/vpVideoReader.h>
62 #include <visp3/io/vpParseArgv.h>
63 #include <visp3/mbt/vpMbEdgeTracker.h>
65 #define GETOPTARGS "x:m:i:n:dchtfColw"
67 void usage(
const char *name,
const char *badparam);
68 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
69 std::string &initFile,
bool &displayFeatures,
bool &click_allowed,
bool &display,
70 bool& cao3DModel,
bool& trackCylinder,
bool &useOgre,
bool &useScanline);
72 void usage(
const char *name,
const char *badparam)
75 Example of tracking based on the 3D model.\n\
78 %s [-i <test image path>] [-x <config file>]\n\
79 [-m <model name>] [-n <initialisation file base name>]\n\
80 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l]",
85 -i <input image path> \n\
86 Set image input path.\n\
87 From this path read images \n\
88 \"ViSP-images/mbt/cube/image%%04d.ppm\". These \n\
89 images come from ViSP-images-x.y.z.tar.gz available \n\
90 on the ViSP website.\n\
91 Setting the VISP_INPUT_IMAGE_PATH environment\n\
92 variable produces the same behaviour than using\n\
96 Set the config file (the xml file) to use.\n\
97 The config file is used to specify the parameters of the tracker.\n\
100 Specify the name of the file of the model\n\
101 The model can either be a vrml model (.wrl) or a .cao file.\n\
104 Do not use the vrml model, use the .cao one. These two models are \n\
105 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
106 website. However, the .cao model allows to use the 3d model based tracker \n\
110 Track only the cube (not the cylinder). In this case the models files are\n\
111 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
112 cube_and_cylinder.wrl.\n\
114 -n <initialisation file base name> \n\
115 Base name of the initialisation file. The file will be 'base_name'.init .\n\
116 This base name is also used for the optionnal picture specifying where to \n\
117 click (a .ppm picture).\
120 Turn off the display of the the moving edges. \n\
123 Turn off the display.\n\
126 Disable the mouse click. Useful to automaze the \n\
127 execution of this program without humain intervention.\n\
130 Use Ogre3D for visibility tests.\n\
133 When Ogre3D is enable [-o] show Ogre3D configuration dialog thatallows to set the renderer.\n\
136 Use the scanline for visibility tests\n\
139 Print the help.\n\n");
142 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
146 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
147 std::string &initFile,
bool &displayFeatures,
bool &click_allowed,
bool &display,
148 bool& cao3DModel,
bool& trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline)
155 case 'i': ipath = optarg_;
break;
156 case 'x': configFile = optarg_;
break;
157 case 'm': modelFile = optarg_;
break;
158 case 'n': initFile = optarg_;
break;
159 case 't': displayFeatures =
false;
break;
160 case 'f': cao3DModel =
true;
break;
161 case 'c': click_allowed =
false;
break;
162 case 'd': display =
false;
break;
163 case 'C': trackCylinder =
false;
break;
164 case 'o': useOgre =
true;
break;
165 case 'l': useScanline =
true;
break;
166 case 'w': showOgreConfigDialog =
true;
break;
167 case 'h': usage(argv[0], NULL);
return false;
break;
170 usage(argv[0], optarg_);
175 if ((c == 1) || (c == -1)) {
177 usage(argv[0], NULL);
178 std::cerr <<
"ERROR: " << std::endl;
179 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
187 main(
int argc,
const char ** argv)
190 std::string env_ipath;
191 std::string opt_ipath;
193 std::string opt_configFile;
194 std::string configFile;
195 std::string opt_modelFile;
196 std::string modelFile;
197 std::string opt_initFile;
198 std::string initFile;
199 bool displayFeatures =
true;
200 bool opt_click_allowed =
true;
201 bool opt_display =
true;
202 bool cao3DModel =
false;
203 bool trackCylinder =
true;
204 bool useOgre =
false;
205 bool showOgreConfigDialog =
false;
206 bool useScanline =
false;
213 if (! env_ipath.empty())
218 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayFeatures,
219 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
225 if (opt_ipath.empty() && env_ipath.empty() ){
226 usage(argv[0], NULL);
227 std::cerr << std::endl
228 <<
"ERROR:" << std::endl;
229 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
231 <<
" environment variable to specify the location of the " << std::endl
232 <<
" image path where test images are located." << std::endl
239 if (!opt_ipath.empty())
244 if (!opt_configFile.empty())
245 configFile = opt_configFile;
246 else if (!opt_ipath.empty())
251 if (!opt_modelFile.empty()){
252 modelFile = opt_modelFile;
254 std::string modelFileCao;
255 std::string modelFileWrl;
257 modelFileCao =
"ViSP-images/mbt/cube_and_cylinder.cao";
258 modelFileWrl =
"ViSP-images/mbt/cube_and_cylinder.wrl";
260 modelFileCao =
"ViSP-images/mbt/cube.cao";
261 modelFileWrl =
"ViSP-images/mbt/cube.wrl";
264 if(!opt_ipath.empty()){
269 #ifdef VISP_HAVE_COIN3D
272 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
282 #ifdef VISP_HAVE_COIN3D
285 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
292 if (!opt_initFile.empty())
293 initFile = opt_initFile;
294 else if (!opt_ipath.empty())
306 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
313 #if defined VISP_HAVE_X11
315 #elif defined VISP_HAVE_GDI
317 #elif defined VISP_HAVE_OPENCV
319 #elif defined VISP_HAVE_D3D9
321 #elif defined VISP_HAVE_GTK
328 #if (defined VISP_HAVE_DISPLAY)
329 display.
init(I, 100, 100,
"Test tracking") ;
340 #if defined (VISP_HAVE_XML2)
381 if (opt_display && opt_click_allowed)
397 if (opt_display && opt_click_allowed)
406 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
420 while (!reader.
end())
434 #if defined (VISP_HAVE_XML2)
467 cMo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
494 if (opt_click_allowed) {
509 if (opt_click_allowed && !quit) {
514 #if defined (VISP_HAVE_XML2)
519 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION == 3)
529 std::cout <<
"Catch an exception: " << e << std::endl;
538 std::cout <<
"visp_mbt module is required to run this example." << std::endl;
void setMovingEdge(const vpMe &me)
long getFrameIndex() const
long getFirstFrameIndex() const
virtual unsigned int getClipping() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
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 setSampleStep(const double &s)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
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)
Make the complete tracking of an object by using its CAD model.
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
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)
virtual void setOgreVisibilityTest(const bool &v)
void setOgreShowConfigDialog(const bool showConfigDialog)
void open(vpImage< vpRGBa > &I)
Display for windows using Direct3D.
virtual void setScanLineVisibilityTest(const bool &v)
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)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, vpImagePoint offset=vpImagePoint(0, 0))
void setMu2(const double &mu_2)
virtual void loadModel(const char *modelFile, const bool verbose=false)
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 bool getClick(bool blocking=true)=0
void setDisplayFeatures(const bool displayF)
void setRange(const unsigned int &r)
virtual void setClipping(const unsigned int &flags)