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:dchtfColwvp"
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 &showOgreConfigDialog,
71 bool &useScanline,
bool &computeCovariance,
bool &projectionError);
73 void usage(
const char *name,
const char *badparam)
76 Example of tracking based on the 3D model.\n\
79 %s [-i <test image path>] [-x <config file>]\n\
80 [-m <model name>] [-n <initialisation file base name>]\n\
81 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]",
86 -i <input image path> \n\
87 Set image input path.\n\
88 From this path read images \n\
89 \"ViSP-images/mbt/cube/image%%04d.ppm\". These \n\
90 images come from ViSP-images-x.y.z.tar.gz available \n\
91 on the ViSP website.\n\
92 Setting the VISP_INPUT_IMAGE_PATH environment\n\
93 variable produces the same behaviour than using\n\
97 Set the config file (the xml file) to use.\n\
98 The config file is used to specify the parameters of the tracker.\n\
101 Specify the name of the file of the model\n\
102 The model can either be a vrml model (.wrl) or a .cao file.\n\
105 Do not use the vrml model, use the .cao one. These two models are \n\
106 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
107 website. However, the .cao model allows to use the 3d model based tracker \n\
111 Track only the cube (not the cylinder). In this case the models files are\n\
112 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
113 cube_and_cylinder.wrl.\n\
115 -n <initialisation file base name> \n\
116 Base name of the initialisation file. The file will be 'base_name'.init .\n\
117 This base name is also used for the optionnal picture specifying where to \n\
118 click (a .ppm picture).\
121 Turn off the display of the the moving edges. \n\
124 Turn off the display.\n\
127 Disable the mouse click. Useful to automaze the \n\
128 execution of this program without humain intervention.\n\
131 Use Ogre3D for visibility tests.\n\
134 When Ogre3D is enable [-o] show Ogre3D configuration dialog thatallows to set the renderer.\n\
137 Use the scanline for visibility tests.\n\
140 Compute covariance matrix.\n\
143 Compute gradient projection error.\n\
146 Print the help.\n\n");
149 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
153 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
154 std::string &initFile,
bool &displayFeatures,
bool &click_allowed,
bool &display,
155 bool& cao3DModel,
bool& trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
156 bool &useScanline,
bool &computeCovariance,
bool &projectionError)
163 case 'i': ipath = optarg_;
break;
164 case 'x': configFile = optarg_;
break;
165 case 'm': modelFile = optarg_;
break;
166 case 'n': initFile = optarg_;
break;
167 case 't': displayFeatures =
false;
break;
168 case 'f': cao3DModel =
true;
break;
169 case 'c': click_allowed =
false;
break;
170 case 'd': display =
false;
break;
171 case 'C': trackCylinder =
false;
break;
172 case 'o': useOgre =
true;
break;
173 case 'l': useScanline =
true;
break;
174 case 'w': showOgreConfigDialog =
true;
break;
175 case 'v': computeCovariance =
true;
break;
176 case 'p': projectionError =
true;
break;
177 case 'h': usage(argv[0], NULL);
return false;
break;
180 usage(argv[0], optarg_);
185 if ((c == 1) || (c == -1)) {
187 usage(argv[0], NULL);
188 std::cerr <<
"ERROR: " << std::endl;
189 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
197 main(
int argc,
const char ** argv)
200 std::string env_ipath;
201 std::string opt_ipath;
203 std::string opt_configFile;
204 std::string configFile;
205 std::string opt_modelFile;
206 std::string modelFile;
207 std::string opt_initFile;
208 std::string initFile;
209 bool displayFeatures =
true;
210 bool opt_click_allowed =
true;
211 bool opt_display =
true;
212 bool cao3DModel =
false;
213 bool trackCylinder =
true;
214 bool useOgre =
false;
215 bool showOgreConfigDialog =
false;
216 bool useScanline =
false;
217 bool computeCovariance =
false;
218 bool projectionError =
false;
225 if (! env_ipath.empty())
230 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayFeatures,
231 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
232 useScanline, computeCovariance, projectionError)) {
237 if (opt_ipath.empty() && env_ipath.empty() ){
238 usage(argv[0], NULL);
239 std::cerr << std::endl
240 <<
"ERROR:" << std::endl;
241 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
243 <<
" environment variable to specify the location of the " << std::endl
244 <<
" image path where test images are located." << std::endl
251 if (!opt_ipath.empty())
256 if (!opt_configFile.empty())
257 configFile = opt_configFile;
258 else if (!opt_ipath.empty())
263 if (!opt_modelFile.empty()){
264 modelFile = opt_modelFile;
266 std::string modelFileCao;
267 std::string modelFileWrl;
269 modelFileCao =
"ViSP-images/mbt/cube_and_cylinder.cao";
270 modelFileWrl =
"ViSP-images/mbt/cube_and_cylinder.wrl";
272 modelFileCao =
"ViSP-images/mbt/cube.cao";
273 modelFileWrl =
"ViSP-images/mbt/cube.wrl";
276 if(!opt_ipath.empty()){
281 #ifdef VISP_HAVE_COIN3D
284 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
294 #ifdef VISP_HAVE_COIN3D
297 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
304 if (!opt_initFile.empty())
305 initFile = opt_initFile;
306 else if (!opt_ipath.empty())
318 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
325 #if defined VISP_HAVE_X11
327 #elif defined VISP_HAVE_GDI
329 #elif defined VISP_HAVE_OPENCV
331 #elif defined VISP_HAVE_D3D9
333 #elif defined VISP_HAVE_GTK
340 #if (defined VISP_HAVE_DISPLAY)
341 display.
init(I, 100, 100,
"Test tracking") ;
352 #if defined (VISP_HAVE_XML2)
399 if (opt_display && opt_click_allowed)
415 if (opt_display && opt_click_allowed)
424 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
435 while (!reader.
end())
449 #if defined (VISP_HAVE_XML2)
484 cMo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
511 if (opt_click_allowed) {
519 if(computeCovariance) {
520 std::cout <<
"Covariance matrix: \n" << tracker.
getCovarianceMatrix() << std::endl << std::endl;
523 if(projectionError) {
524 std::cout <<
"Projection error: " << tracker.
getProjectionError() << std::endl << std::endl;
530 if (opt_click_allowed && !quit) {
535 #if defined (VISP_HAVE_XML2)
540 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION == 3)
550 std::cout <<
"Catch an exception: " << e << std::endl;
559 std::cout <<
"visp_mbt module is required to run this example." << std::endl;
virtual void setDisplayFeatures(const bool displayF)
virtual void setCovarianceComputation(const bool &flag)
void setMovingEdge(const vpMe &me)
long getFrameIndex() const
long getFirstFrameIndex() const
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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.
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 3rd party. Thus to enable this class Direct3D should be installed...
virtual void setScanLineVisibilityTest(const bool &v)
void setMaskSize(const unsigned int &a)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
virtual void getCameraParameters(vpCameraParameters &camera) const
virtual double getProjectionError() const
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
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)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
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)
virtual void getPose(vpHomogeneousMatrix &cMo_) const
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)
void setRange(const unsigned int &r)
virtual void setClipping(const unsigned int &flags)
virtual void setProjectionErrorComputation(const bool &flag)
virtual vpMatrix getCovarianceMatrix() const