50 #include <visp3/core/vpConfig.h> 52 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY) 54 #include <visp3/core/vpDebug.h> 55 #include <visp3/core/vpHomogeneousMatrix.h> 56 #include <visp3/core/vpIoTools.h> 57 #include <visp3/core/vpMath.h> 58 #include <visp3/gui/vpDisplayD3D.h> 59 #include <visp3/gui/vpDisplayGDI.h> 60 #include <visp3/gui/vpDisplayGTK.h> 61 #include <visp3/gui/vpDisplayOpenCV.h> 62 #include <visp3/gui/vpDisplayX.h> 63 #include <visp3/io/vpImageIo.h> 64 #include <visp3/io/vpParseArgv.h> 65 #include <visp3/io/vpVideoReader.h> 66 #include <visp3/mbt/vpMbEdgeMultiTracker.h> 68 #define GETOPTARGS "x:m:i:n:de:chtfColwvp" 70 void usage(
const char *name,
const char *badparam)
73 Example of tracking based on the 3D model.\n\ 76 %s [-i <test image path>] [-x <config file>]\n\ 77 [-m <model name>] [-n <initialisation file base name>] [-e <last frame index>]\n\ 78 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]\n", name);
82 -i <input image path> \n\ 83 Set image input path.\n\ 84 From this path read images \n\ 85 \"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\ 100 -e <last frame index> \n\ 101 Specify the index of the last frame. Once reached, the tracking is stopped\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 optional picture specifying where to \n\ 117 click (a .ppm picture).\n\ 120 Turn off the display of the the moving edges. \n\ 123 Turn off the display.\n\ 126 Disable the mouse click. Useful to automate the \n\ 127 execution of this program without human intervention.\n\ 130 Use Ogre3D for visibility tests.\n\ 133 When Ogre3D is enable [-o] show Ogre3D configuration dialog that allows to set the renderer.\n\ 136 Use the scanline for visibility tests.\n\ 139 Compute covariance matrix.\n\ 142 Compute gradient projection error.\n\ 145 Print the help.\n\n");
148 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
151 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
152 std::string &initFile,
long &lastFrame,
bool &displayFeatures,
bool &click_allowed,
bool &display,
153 bool &cao3DModel,
bool &trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
154 bool &computeCovariance,
bool &projectionError)
162 lastFrame = atol(optarg_);
168 configFile = optarg_;
177 displayFeatures =
false;
183 click_allowed =
false;
189 trackCylinder =
false;
198 showOgreConfigDialog =
true;
201 computeCovariance =
true;
204 projectionError =
true;
207 usage(argv[0], NULL);
212 usage(argv[0], optarg_);
218 if ((c == 1) || (c == -1)) {
220 usage(argv[0], NULL);
221 std::cerr <<
"ERROR: " << std::endl;
222 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
229 int main(
int argc,
const char **argv)
232 std::string env_ipath;
233 std::string opt_ipath;
235 std::string opt_configFile;
236 std::string configFile;
237 std::string opt_modelFile;
238 std::string modelFile;
239 std::string opt_initFile;
240 std::string initFile;
241 long opt_lastFrame = -1;
242 bool displayFeatures =
true;
243 bool opt_click_allowed =
true;
244 bool opt_display =
true;
245 bool cao3DModel =
false;
246 bool trackCylinder =
true;
247 bool useOgre =
false;
248 bool showOgreConfigDialog =
false;
249 bool useScanline =
false;
250 bool computeCovariance =
false;
251 bool projectionError =
false;
259 if (!env_ipath.empty())
263 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayFeatures,
264 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
265 useScanline, computeCovariance, projectionError)) {
270 if (opt_ipath.empty() && env_ipath.empty()) {
271 usage(argv[0], NULL);
272 std::cerr << std::endl <<
"ERROR:" << std::endl;
273 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
274 <<
" environment variable to specify the location of the " << std::endl
275 <<
" image path where test images are located." << std::endl
282 if (!opt_ipath.empty())
287 if (!opt_configFile.empty())
288 configFile = opt_configFile;
289 else if (!opt_ipath.empty())
294 if (!opt_modelFile.empty()) {
295 modelFile = opt_modelFile;
297 std::string modelFileCao;
298 std::string modelFileWrl;
300 modelFileCao =
"mbt/cube_and_cylinder.cao";
301 modelFileWrl =
"mbt/cube_and_cylinder.wrl";
303 modelFileCao =
"mbt/cube.cao";
304 modelFileWrl =
"mbt/cube.wrl";
307 if (!opt_ipath.empty()) {
311 #ifdef VISP_HAVE_COIN3D 314 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
322 #ifdef VISP_HAVE_COIN3D 325 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
332 if (!opt_initFile.empty())
333 initFile = opt_initFile;
334 else if (!opt_ipath.empty())
347 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
358 #if defined VISP_HAVE_X11 360 #elif defined VISP_HAVE_GDI 362 #elif defined VISP_HAVE_OPENCV 364 #elif defined VISP_HAVE_D3D9 366 #elif defined VISP_HAVE_GTK 372 #if (defined VISP_HAVE_DISPLAY) 375 display1.
init(I1, 100, 100,
"Test tracking (Left)");
389 #if defined(VISP_HAVE_XML2) 391 tracker.loadConfigFile(configFile, configFile);
406 tracker.setCameraParameters(cam1, cam2);
407 tracker.setMovingEdge(me);
410 tracker.setNearClippingDistance(0.01);
411 tracker.setFarClippingDistance(0.90);
420 tracker.setDisplayFeatures(displayFeatures);
423 tracker.setOgreVisibilityTest(useOgre);
425 tracker.setOgreShowConfigDialog(showOgreConfigDialog);
428 tracker.setScanLineVisibilityTest(useScanline);
431 tracker.setCovarianceComputation(computeCovariance);
434 tracker.setProjectionErrorComputation(projectionError);
437 tracker.getCameraParameters(cam1, cam2);
440 std::map<std::string, vpHomogeneousMatrix> mapOfCamTrans;
443 tracker.setCameraTransformationMatrix(mapOfCamTrans);
446 if (opt_display && opt_click_allowed) {
456 tracker.loadModel(modelFile);
464 if (opt_display && opt_click_allowed) {
465 tracker.initClick(I1, I2, initFile, initFile,
true);
466 tracker.getPose(c1Mo, c2Mo);
468 tracker.display(I1, I2, c1Mo, c2Mo, cam1, cam2,
vpColor::red);
470 vpHomogeneousMatrix c1Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
471 vpHomogeneousMatrix c2Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
472 tracker.initFromPose(I1, I2, c1Moi, c2Moi);
476 tracker.track(I1, I2);
477 tracker.getPose(c1Mo, c2Mo);
484 while (!reader.
end()) {
497 std::cout <<
"----------Test reset tracker----------" << std::endl;
502 tracker.resetTracker();
503 #if defined(VISP_HAVE_XML2) 504 tracker.loadConfigFile(configFile, configFile);
519 tracker.setCameraParameters(cam1, cam2);
520 tracker.setMovingEdge(me);
523 tracker.setNearClippingDistance(0.01);
524 tracker.setFarClippingDistance(0.90);
530 tracker.loadModel(modelFile);
531 tracker.setCameraParameters(cam1, cam2);
532 tracker.setOgreVisibilityTest(useOgre);
533 tracker.setScanLineVisibilityTest(useScanline);
534 tracker.setCovarianceComputation(computeCovariance);
535 tracker.setProjectionErrorComputation(projectionError);
536 tracker.initFromPose(I1, I2, c1Mo, c2Mo);
541 c1Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
542 c2Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
543 std::cout <<
"Test set pose" << std::endl;
544 tracker.setPose(I1, I2, c1Mo, c2Mo);
550 tracker.track(I1, I2);
551 tracker.getPose(c1Mo, c2Mo);
561 if (opt_click_allowed) {
569 if (computeCovariance) {
570 std::cout <<
"Covariance matrix: \n" << tracker.getCovarianceMatrix() << std::endl << std::endl;
573 if (projectionError) {
574 std::cout <<
"Projection error: " << tracker.getProjectionError() << std::endl << std::endl;
581 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
583 if (opt_click_allowed && !quit) {
588 #if defined(VISP_HAVE_XML2) 594 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION == 2 || COIN_MAJOR_VERSION == 3) 603 std::cout <<
"Catch an exception: " << e << std::endl;
612 std::cout <<
"visp_mbt module is required to run this example." << std::endl;
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 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)
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 setRange(const unsigned int &r)
unsigned int getWidth() const
Make the complete stereo (or more) tracking of an object by using its CAD model.