48 #include <visp3/core/vpConfig.h>
50 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY)
52 #include <visp3/core/vpDebug.h>
53 #include <visp3/gui/vpDisplayD3D.h>
54 #include <visp3/gui/vpDisplayGTK.h>
55 #include <visp3/gui/vpDisplayGDI.h>
56 #include <visp3/gui/vpDisplayOpenCV.h>
57 #include <visp3/gui/vpDisplayX.h>
58 #include <visp3/core/vpHomogeneousMatrix.h>
59 #include <visp3/io/vpImageIo.h>
60 #include <visp3/core/vpIoTools.h>
61 #include <visp3/core/vpMath.h>
62 #include <visp3/io/vpVideoReader.h>
63 #include <visp3/io/vpParseArgv.h>
64 #include <visp3/mbt/vpMbEdgeMultiTracker.h>
66 #define GETOPTARGS "x:m:i:n:dchtfColwvp"
69 void usage(
const char *name,
const char *badparam)
72 Example of tracking based on the 3D model.\n\
75 %s [-i <test image path>] [-x <config file>]\n\
76 [-m <model name>] [-n <initialisation file base name>]\n\
77 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]",
82 -i <input image path> \n\
83 Set image input path.\n\
84 From this path read images \n\
85 \"ViSP-images/mbt/cube/image%%04d.ppm\". These \n\
86 images come from ViSP-images-x.y.z.tar.gz available \n\
87 on the ViSP website.\n\
88 Setting the VISP_INPUT_IMAGE_PATH environment\n\
89 variable produces the same behavior than using\n\
93 Set the config file (the xml file) to use.\n\
94 The config file is used to specify the parameters of the tracker.\n\
97 Specify the name of the file of the model\n\
98 The model can either be a vrml model (.wrl) or a .cao file.\n\
101 Do not use the vrml model, use the .cao one. These two models are \n\
102 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
103 website. However, the .cao model allows to use the 3d model based tracker \n\
107 Track only the cube (not the cylinder). In this case the models files are\n\
108 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
109 cube_and_cylinder.wrl.\n\
111 -n <initialisation file base name> \n\
112 Base name of the initialisation file. The file will be 'base_name'.init .\n\
113 This base name is also used for the optional picture specifying where to \n\
114 click (a .ppm picture).\
117 Turn off the display of the the moving edges. \n\
120 Turn off the display.\n\
123 Disable the mouse click. Useful to automate the \n\
124 execution of this program without human intervention.\n\
127 Use Ogre3D for visibility tests.\n\
130 When Ogre3D is enable [-o] show Ogre3D configuration dialog that allows to set the renderer.\n\
133 Use the scanline for visibility tests.\n\
136 Compute covariance matrix.\n\
139 Compute gradient projection error.\n\
142 Print the help.\n\n");
145 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
149 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
150 std::string &initFile,
bool &displayFeatures,
bool &click_allowed,
bool &display,
151 bool& cao3DModel,
bool& trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
152 bool &useScanline,
bool &computeCovariance,
bool &projectionError)
159 case 'i': ipath = optarg_;
break;
160 case 'x': configFile = optarg_;
break;
161 case 'm': modelFile = optarg_;
break;
162 case 'n': initFile = optarg_;
break;
163 case 't': displayFeatures =
false;
break;
164 case 'f': cao3DModel =
true;
break;
165 case 'c': click_allowed =
false;
break;
166 case 'd': display =
false;
break;
167 case 'C': trackCylinder =
false;
break;
168 case 'o': useOgre =
true;
break;
169 case 'l': useScanline =
true;
break;
170 case 'w': showOgreConfigDialog =
true;
break;
171 case 'v': computeCovariance =
true;
break;
172 case 'p': projectionError =
true;
break;
173 case 'h': usage(argv[0], NULL);
return false;
break;
176 usage(argv[0], optarg_);
181 if ((c == 1) || (c == -1)) {
183 usage(argv[0], NULL);
184 std::cerr <<
"ERROR: " << std::endl;
185 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
193 main(
int argc,
const char ** argv)
196 std::string env_ipath;
197 std::string opt_ipath;
199 std::string opt_configFile;
200 std::string configFile;
201 std::string opt_modelFile;
202 std::string modelFile;
203 std::string opt_initFile;
204 std::string initFile;
205 bool displayFeatures =
true;
206 bool opt_click_allowed =
true;
207 bool opt_display =
true;
208 bool cao3DModel =
false;
209 bool trackCylinder =
true;
210 bool useOgre =
false;
211 bool showOgreConfigDialog =
false;
212 bool useScanline =
false;
213 bool computeCovariance =
false;
214 bool projectionError =
false;
221 if (! env_ipath.empty())
226 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayFeatures,
227 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
228 useScanline, computeCovariance, projectionError)) {
233 if (opt_ipath.empty() && env_ipath.empty() ){
234 usage(argv[0], NULL);
235 std::cerr << std::endl
236 <<
"ERROR:" << std::endl;
237 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
239 <<
" environment variable to specify the location of the " << std::endl
240 <<
" image path where test images are located." << std::endl
247 if (!opt_ipath.empty())
252 if (!opt_configFile.empty())
253 configFile = opt_configFile;
254 else if (!opt_ipath.empty())
259 if (!opt_modelFile.empty()){
260 modelFile = opt_modelFile;
262 std::string modelFileCao;
263 std::string modelFileWrl;
265 modelFileCao =
"ViSP-images/mbt/cube_and_cylinder.cao";
266 modelFileWrl =
"ViSP-images/mbt/cube_and_cylinder.wrl";
268 modelFileCao =
"ViSP-images/mbt/cube.cao";
269 modelFileWrl =
"ViSP-images/mbt/cube.wrl";
272 if(!opt_ipath.empty()){
277 #ifdef VISP_HAVE_COIN3D
280 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
290 #ifdef VISP_HAVE_COIN3D
293 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
300 if (!opt_initFile.empty())
301 initFile = opt_initFile;
302 else if (!opt_ipath.empty())
315 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
323 #if defined VISP_HAVE_X11
325 #elif defined VISP_HAVE_GDI
327 #elif defined VISP_HAVE_OPENCV
329 #elif defined VISP_HAVE_D3D9
331 #elif defined VISP_HAVE_GTK
338 #if (defined VISP_HAVE_DISPLAY)
341 display1.
init(I1, 100, 100,
"Test tracking (Left)");
355 #if defined (VISP_HAVE_XML2)
357 tracker.loadConfigFile(configFile, configFile);
372 tracker.setCameraParameters(cam1, cam2);
373 tracker.setMovingEdge(me);
376 tracker.setNearClippingDistance(0.01);
377 tracker.setFarClippingDistance(0.90);
383 tracker.setDisplayFeatures(displayFeatures);
386 tracker.setOgreVisibilityTest(useOgre);
388 tracker.setOgreShowConfigDialog(showOgreConfigDialog);
391 tracker.setScanLineVisibilityTest(useScanline);
394 tracker.setCovarianceComputation(computeCovariance);
397 tracker.setProjectionErrorComputation(projectionError);
400 tracker.getCameraParameters(cam1, cam2);
403 std::map<std::string, vpHomogeneousMatrix> mapOfCamTrans;
406 tracker.setCameraTransformationMatrix(mapOfCamTrans);
409 if (opt_display && opt_click_allowed)
420 tracker.loadModel(modelFile);
426 if (opt_display && opt_click_allowed)
428 tracker.initClick(I1, I2, initFile, initFile,
true);
429 tracker.getPose(c1Mo, c2Mo);
431 tracker.display(I1, I2, c1Mo, c2Mo, cam1, cam2,
vpColor::red);
435 vpHomogeneousMatrix c1Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
436 vpHomogeneousMatrix c2Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
437 tracker.initFromPose(I1, I2, c1Moi, c2Moi);
441 tracker.track(I1, I2);
442 tracker.getPose(c1Mo, c2Mo);
449 while (!reader.
end())
463 std::cout <<
"----------Test reset tracker----------" << std::endl;
468 tracker.resetTracker();
469 #if defined (VISP_HAVE_XML2)
470 tracker.loadConfigFile(configFile, configFile);
485 tracker.setCameraParameters(cam1, cam2);
486 tracker.setMovingEdge(me);
489 tracker.setNearClippingDistance(0.01);
490 tracker.setFarClippingDistance(0.90);
494 tracker.loadModel(modelFile);
495 tracker.setCameraParameters(cam1, cam2);
496 tracker.setOgreVisibilityTest(useOgre);
497 tracker.setScanLineVisibilityTest(useScanline);
498 tracker.setCovarianceComputation(computeCovariance);
499 tracker.setProjectionErrorComputation(projectionError);
500 tracker.initFromPose(I1, I2, c1Mo, c2Mo);
505 c1Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
506 c2Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
507 std::cout <<
"Test set pose" << std::endl;
508 tracker.setPose(I1, I2, c1Mo, c2Mo);
513 tracker.track(I1, I2);
514 tracker.getPose(c1Mo, c2Mo);
524 if (opt_click_allowed) {
532 if(computeCovariance) {
533 std::cout <<
"Covariance matrix: \n" << tracker.getCovarianceMatrix() << std::endl << std::endl;
536 if(projectionError) {
537 std::cout <<
"Projection error: " << tracker.getProjectionError() << std::endl << std::endl;
544 if (opt_click_allowed && !quit) {
549 #if defined (VISP_HAVE_XML2)
554 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION == 2 || COIN_MAJOR_VERSION == 3)
564 std::cout <<
"Catch an exception: " << e << std::endl;
573 std::cout <<
"visp_mbt module is required to run this example." << std::endl;
VISP_EXPORT int wait(double t0, double t)
long getFrameIndex() const
long getFirstFrameIndex() const
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
unsigned int getWidth() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setMaskNumber(const unsigned int &a)
virtual void setDownScalingFactor(unsigned int scale)
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.
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)
void open(vpImage< vpRGBa > &I)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
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...
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)
void setFileName(const char *filename)
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)
unsigned int getDownScalingFactor()
void setThreshold(const double &t)
void setRange(const unsigned int &r)
Make the complete stereo (or more) tracking of an object by using its CAD model.