50 #include <visp3/core/vpConfig.h> 52 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) 54 #if (defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY)) \ 55 && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)) 57 #include <visp3/core/vpDebug.h> 58 #include <visp3/core/vpHomogeneousMatrix.h> 59 #include <visp3/core/vpIoTools.h> 60 #include <visp3/core/vpMath.h> 61 #include <visp3/gui/vpDisplayD3D.h> 62 #include <visp3/gui/vpDisplayGDI.h> 63 #include <visp3/gui/vpDisplayGTK.h> 64 #include <visp3/gui/vpDisplayOpenCV.h> 65 #include <visp3/gui/vpDisplayX.h> 66 #include <visp3/io/vpImageIo.h> 67 #include <visp3/io/vpParseArgv.h> 68 #include <visp3/io/vpVideoReader.h> 69 #include <visp3/mbt/vpMbEdgeMultiTracker.h> 71 #define GETOPTARGS "x:m:i:n:de:chtfColwvp" 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>] [-e <last frame index>]\n\ 81 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]\n", name);
85 -i <input image path> \n\ 86 Set image input path.\n\ 87 From this path read images \n\ 88 \"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 behavior 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\ 103 -e <last frame index> \n\ 104 Specify the index of the last frame. Once reached, the tracking is stopped\n\ 107 Do not use the vrml model, use the .cao one. These two models are \n\ 108 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\ 109 website. However, the .cao model allows to use the 3d model based tracker \n\ 113 Track only the cube (not the cylinder). In this case the models files are\n\ 114 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\ 115 cube_and_cylinder.wrl.\n\ 117 -n <initialisation file base name> \n\ 118 Base name of the initialisation file. The file will be 'base_name'.init .\n\ 119 This base name is also used for the optional picture specifying where to \n\ 120 click (a .ppm picture).\n\ 123 Turn off the display of the the moving edges. \n\ 126 Turn off the display.\n\ 129 Disable the mouse click. Useful to automate the \n\ 130 execution of this program without human intervention.\n\ 133 Use Ogre3D for visibility tests.\n\ 136 When Ogre3D is enable [-o] show Ogre3D configuration dialog that allows to set the renderer.\n\ 139 Use the scanline for visibility tests.\n\ 142 Compute covariance matrix.\n\ 145 Compute gradient projection error.\n\ 148 Print the help.\n\n");
151 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
154 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
155 std::string &initFile,
long &lastFrame,
bool &displayFeatures,
bool &click_allowed,
bool &display,
156 bool &cao3DModel,
bool &trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
157 bool &computeCovariance,
bool &projectionError)
165 lastFrame = atol(optarg_);
171 configFile = optarg_;
180 displayFeatures =
false;
186 click_allowed =
false;
192 trackCylinder =
false;
201 showOgreConfigDialog =
true;
204 computeCovariance =
true;
207 projectionError =
true;
210 usage(argv[0], NULL);
215 usage(argv[0], optarg_);
221 if ((c == 1) || (c == -1)) {
223 usage(argv[0], NULL);
224 std::cerr <<
"ERROR: " << std::endl;
225 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
232 int main(
int argc,
const char **argv)
235 std::string env_ipath;
236 std::string opt_ipath;
238 std::string opt_configFile;
239 std::string configFile;
240 std::string opt_modelFile;
241 std::string modelFile;
242 std::string opt_initFile;
243 std::string initFile;
244 long opt_lastFrame = -1;
245 bool displayFeatures =
true;
246 bool opt_click_allowed =
true;
247 bool opt_display =
true;
248 bool cao3DModel =
false;
249 bool trackCylinder =
true;
250 bool useOgre =
false;
251 bool showOgreConfigDialog =
false;
252 bool useScanline =
false;
253 bool computeCovariance =
false;
254 bool projectionError =
false;
262 if (!env_ipath.empty())
266 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayFeatures,
267 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
268 useScanline, computeCovariance, projectionError)) {
273 if (opt_ipath.empty() && env_ipath.empty()) {
274 usage(argv[0], NULL);
275 std::cerr << std::endl <<
"ERROR:" << std::endl;
276 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
277 <<
" environment variable to specify the location of the " << std::endl
278 <<
" image path where test images are located." << std::endl
285 if (!opt_ipath.empty())
290 if (!opt_configFile.empty())
291 configFile = opt_configFile;
292 else if (!opt_ipath.empty())
297 if (!opt_modelFile.empty()) {
298 modelFile = opt_modelFile;
300 std::string modelFileCao;
301 std::string modelFileWrl;
303 modelFileCao =
"mbt/cube_and_cylinder.cao";
304 modelFileWrl =
"mbt/cube_and_cylinder.wrl";
306 modelFileCao =
"mbt/cube.cao";
307 modelFileWrl =
"mbt/cube.wrl";
310 if (!opt_ipath.empty()) {
314 #ifdef VISP_HAVE_COIN3D 317 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
325 #ifdef VISP_HAVE_COIN3D 328 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
335 if (!opt_initFile.empty())
336 initFile = opt_initFile;
337 else if (!opt_ipath.empty())
350 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
361 #if defined VISP_HAVE_X11 363 #elif defined VISP_HAVE_GDI 365 #elif defined VISP_HAVE_OPENCV 367 #elif defined VISP_HAVE_D3D9 369 #elif defined VISP_HAVE_GTK 375 #if defined(VISP_HAVE_DISPLAY) 378 display1.
init(I1, 100, 100,
"Test tracking (Left)");
392 #if defined(VISP_HAVE_PUGIXML) 394 tracker.loadConfigFile(configFile, configFile);
409 tracker.setCameraParameters(cam1, cam2);
410 tracker.setMovingEdge(me);
413 tracker.setNearClippingDistance(0.01);
414 tracker.setFarClippingDistance(0.90);
423 tracker.setDisplayFeatures(displayFeatures);
426 tracker.setOgreVisibilityTest(useOgre);
428 tracker.setOgreShowConfigDialog(showOgreConfigDialog);
431 tracker.setScanLineVisibilityTest(useScanline);
434 tracker.setCovarianceComputation(computeCovariance);
437 tracker.setProjectionErrorComputation(projectionError);
440 tracker.getCameraParameters(cam1, cam2);
443 std::map<std::string, vpHomogeneousMatrix> mapOfCamTrans;
446 tracker.setCameraTransformationMatrix(mapOfCamTrans);
449 if (opt_display && opt_click_allowed) {
459 tracker.loadModel(modelFile);
467 if (opt_display && opt_click_allowed) {
468 tracker.initClick(I1, I2, initFile, initFile,
true);
469 tracker.getPose(c1Mo, c2Mo);
471 tracker.display(I1, I2, c1Mo, c2Mo, cam1, cam2,
vpColor::red);
473 vpHomogeneousMatrix c1Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
474 vpHomogeneousMatrix c2Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
475 tracker.initFromPose(I1, I2, c1Moi, c2Moi);
479 tracker.track(I1, I2);
480 tracker.getPose(c1Mo, c2Mo);
487 while (!reader.
end()) {
500 std::cout <<
"----------Test reset tracker----------" << std::endl;
505 tracker.resetTracker();
506 #if defined(VISP_HAVE_PUGIXML) 507 tracker.loadConfigFile(configFile, configFile);
522 tracker.setCameraParameters(cam1, cam2);
523 tracker.setMovingEdge(me);
526 tracker.setNearClippingDistance(0.01);
527 tracker.setFarClippingDistance(0.90);
533 tracker.loadModel(modelFile);
534 tracker.setCameraParameters(cam1, cam2);
535 tracker.setOgreVisibilityTest(useOgre);
536 tracker.setScanLineVisibilityTest(useScanline);
537 tracker.setCovarianceComputation(computeCovariance);
538 tracker.setProjectionErrorComputation(projectionError);
539 tracker.initFromPose(I1, I2, c1Mo, c2Mo);
544 c1Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
545 c2Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
546 std::cout <<
"Test set pose" << std::endl;
547 tracker.setPose(I1, I2, c1Mo, c2Mo);
553 tracker.track(I1, I2);
554 tracker.getPose(c1Mo, c2Mo);
564 if (opt_click_allowed) {
572 if (computeCovariance) {
573 std::cout <<
"Covariance matrix: \n" << tracker.getCovarianceMatrix() << std::endl << std::endl;
576 if (projectionError) {
577 std::cout <<
"Projection error: " << tracker.getProjectionError() << std::endl << std::endl;
586 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
588 if (opt_click_allowed && !quit) {
593 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION >= 2) 602 std::cout <<
"Catch an exception: " << e << std::endl;
607 #elif !(defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY)) 610 std::cout <<
"Cannot run this example: visp_mbt, visp_gui modules are required." 617 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
625 std::cout <<
"Nothing to run, deprecated example." << std::endl;
628 #endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) VISP_EXPORT int wait(double t0, double t)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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 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 buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void setMu2(const double &mu_2)
long getFrameIndex() const
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 setFileName(const std::string &filename)
void setRange(const unsigned int &r)
unsigned int getWidth() const
Make the complete stereo (or more) tracking of an object by using its CAD model.