50 #include <visp3/core/vpConfig.h> 52 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) 54 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY) 56 #include <visp3/core/vpDebug.h> 57 #include <visp3/core/vpHomogeneousMatrix.h> 58 #include <visp3/core/vpIoTools.h> 59 #include <visp3/core/vpMath.h> 60 #include <visp3/gui/vpDisplayD3D.h> 61 #include <visp3/gui/vpDisplayGDI.h> 62 #include <visp3/gui/vpDisplayGTK.h> 63 #include <visp3/gui/vpDisplayOpenCV.h> 64 #include <visp3/gui/vpDisplayX.h> 65 #include <visp3/io/vpImageIo.h> 66 #include <visp3/io/vpParseArgv.h> 67 #include <visp3/io/vpVideoReader.h> 68 #include <visp3/mbt/vpMbEdgeMultiTracker.h> 70 #define GETOPTARGS "x:m:i:n:de:chtfColwvp" 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>] [-e <last frame index>]\n\ 80 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]\n", name);
84 -i <input image path> \n\ 85 Set image input path.\n\ 86 From this path read images \n\ 87 \"mbt/cube/image%%04d.ppm\". These \n\ 88 images come from ViSP-images-x.y.z.tar.gz available \n\ 89 on the ViSP website.\n\ 90 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 91 variable produces the same behavior than using\n\ 95 Set the config file (the xml file) to use.\n\ 96 The config file is used to specify the parameters of the tracker.\n\ 99 Specify the name of the file of the model\n\ 100 The model can either be a vrml model (.wrl) or a .cao file.\n\ 102 -e <last frame index> \n\ 103 Specify the index of the last frame. Once reached, the tracking is stopped\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 optional picture specifying where to \n\ 119 click (a .ppm picture).\n\ 122 Turn off the display of the the moving edges. \n\ 125 Turn off the display.\n\ 128 Disable the mouse click. Useful to automate the \n\ 129 execution of this program without human intervention.\n\ 132 Use Ogre3D for visibility tests.\n\ 135 When Ogre3D is enable [-o] show Ogre3D configuration dialog that allows to set the renderer.\n\ 138 Use the scanline for visibility tests.\n\ 141 Compute covariance matrix.\n\ 144 Compute gradient projection error.\n\ 147 Print the help.\n\n");
150 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,
long &lastFrame,
bool &displayFeatures,
bool &click_allowed,
bool &display,
155 bool &cao3DModel,
bool &trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
156 bool &computeCovariance,
bool &projectionError)
164 lastFrame = atol(optarg_);
170 configFile = optarg_;
179 displayFeatures =
false;
185 click_allowed =
false;
191 trackCylinder =
false;
200 showOgreConfigDialog =
true;
203 computeCovariance =
true;
206 projectionError =
true;
209 usage(argv[0], NULL);
214 usage(argv[0], optarg_);
220 if ((c == 1) || (c == -1)) {
222 usage(argv[0], NULL);
223 std::cerr <<
"ERROR: " << std::endl;
224 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
231 int main(
int argc,
const char **argv)
234 std::string env_ipath;
235 std::string opt_ipath;
237 std::string opt_configFile;
238 std::string configFile;
239 std::string opt_modelFile;
240 std::string modelFile;
241 std::string opt_initFile;
242 std::string initFile;
243 long opt_lastFrame = -1;
244 bool displayFeatures =
true;
245 bool opt_click_allowed =
true;
246 bool opt_display =
true;
247 bool cao3DModel =
false;
248 bool trackCylinder =
true;
249 bool useOgre =
false;
250 bool showOgreConfigDialog =
false;
251 bool useScanline =
false;
252 bool computeCovariance =
false;
253 bool projectionError =
false;
261 if (!env_ipath.empty())
265 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayFeatures,
266 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
267 useScanline, computeCovariance, projectionError)) {
272 if (opt_ipath.empty() && env_ipath.empty()) {
273 usage(argv[0], NULL);
274 std::cerr << std::endl <<
"ERROR:" << std::endl;
275 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
276 <<
" environment variable to specify the location of the " << std::endl
277 <<
" image path where test images are located." << std::endl
284 if (!opt_ipath.empty())
289 if (!opt_configFile.empty())
290 configFile = opt_configFile;
291 else if (!opt_ipath.empty())
296 if (!opt_modelFile.empty()) {
297 modelFile = opt_modelFile;
299 std::string modelFileCao;
300 std::string modelFileWrl;
302 modelFileCao =
"mbt/cube_and_cylinder.cao";
303 modelFileWrl =
"mbt/cube_and_cylinder.wrl";
305 modelFileCao =
"mbt/cube.cao";
306 modelFileWrl =
"mbt/cube.wrl";
309 if (!opt_ipath.empty()) {
313 #ifdef VISP_HAVE_COIN3D 316 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
324 #ifdef VISP_HAVE_COIN3D 327 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
334 if (!opt_initFile.empty())
335 initFile = opt_initFile;
336 else if (!opt_ipath.empty())
349 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
360 #if defined VISP_HAVE_X11 362 #elif defined VISP_HAVE_GDI 364 #elif defined VISP_HAVE_OPENCV 366 #elif defined VISP_HAVE_D3D9 368 #elif defined VISP_HAVE_GTK 374 #if defined(VISP_HAVE_DISPLAY) 377 display1.
init(I1, 100, 100,
"Test tracking (Left)");
391 #if defined(VISP_HAVE_XML2) 393 tracker.loadConfigFile(configFile, configFile);
408 tracker.setCameraParameters(cam1, cam2);
409 tracker.setMovingEdge(me);
412 tracker.setNearClippingDistance(0.01);
413 tracker.setFarClippingDistance(0.90);
422 tracker.setDisplayFeatures(displayFeatures);
425 tracker.setOgreVisibilityTest(useOgre);
427 tracker.setOgreShowConfigDialog(showOgreConfigDialog);
430 tracker.setScanLineVisibilityTest(useScanline);
433 tracker.setCovarianceComputation(computeCovariance);
436 tracker.setProjectionErrorComputation(projectionError);
439 tracker.getCameraParameters(cam1, cam2);
442 std::map<std::string, vpHomogeneousMatrix> mapOfCamTrans;
445 tracker.setCameraTransformationMatrix(mapOfCamTrans);
448 if (opt_display && opt_click_allowed) {
458 tracker.loadModel(modelFile);
466 if (opt_display && opt_click_allowed) {
467 tracker.initClick(I1, I2, initFile, initFile,
true);
468 tracker.getPose(c1Mo, c2Mo);
470 tracker.display(I1, I2, c1Mo, c2Mo, cam1, cam2,
vpColor::red);
472 vpHomogeneousMatrix c1Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
473 vpHomogeneousMatrix c2Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
474 tracker.initFromPose(I1, I2, c1Moi, c2Moi);
478 tracker.track(I1, I2);
479 tracker.getPose(c1Mo, c2Mo);
486 while (!reader.
end()) {
499 std::cout <<
"----------Test reset tracker----------" << std::endl;
504 tracker.resetTracker();
505 #if defined(VISP_HAVE_XML2) 506 tracker.loadConfigFile(configFile, configFile);
521 tracker.setCameraParameters(cam1, cam2);
522 tracker.setMovingEdge(me);
525 tracker.setNearClippingDistance(0.01);
526 tracker.setFarClippingDistance(0.90);
532 tracker.loadModel(modelFile);
533 tracker.setCameraParameters(cam1, cam2);
534 tracker.setOgreVisibilityTest(useOgre);
535 tracker.setScanLineVisibilityTest(useScanline);
536 tracker.setCovarianceComputation(computeCovariance);
537 tracker.setProjectionErrorComputation(projectionError);
538 tracker.initFromPose(I1, I2, c1Mo, c2Mo);
543 c1Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
544 c2Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
545 std::cout <<
"Test set pose" << std::endl;
546 tracker.setPose(I1, I2, c1Mo, c2Mo);
552 tracker.track(I1, I2);
553 tracker.getPose(c1Mo, c2Mo);
563 if (opt_click_allowed) {
571 if (computeCovariance) {
572 std::cout <<
"Covariance matrix: \n" << tracker.getCovarianceMatrix() << std::endl << std::endl;
575 if (projectionError) {
576 std::cout <<
"Projection error: " << tracker.getProjectionError() << std::endl << std::endl;
585 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
587 if (opt_click_allowed && !quit) {
592 #if defined(VISP_HAVE_XML2) 598 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION >= 2) 607 std::cout <<
"Catch an exception: " << e << std::endl;
615 std::cout <<
"visp_mbt module is required to run this example." << std::endl;
622 std::cout <<
"Nothing to run, deprecated example." << std::endl;
625 #endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) VISP_EXPORT int wait(double t0, double t)
long getFrameIndex() 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)
long getFirstFrameIndex()
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="")
void setMu2(const double &mu_2)
void setLastFrameIndex(const long last_frame)
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, const vpImagePoint &offset=vpImagePoint(0, 0))
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.