48 #include <visp3/core/vpConfig.h> 50 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && \ 51 defined(VISP_HAVE_DISPLAY) && (VISP_HAVE_OPENCV_VERSION >= 0x020100) 53 #include <visp3/core/vpDebug.h> 54 #include <visp3/core/vpHomogeneousMatrix.h> 55 #include <visp3/core/vpIoTools.h> 56 #include <visp3/core/vpMath.h> 57 #include <visp3/gui/vpDisplayD3D.h> 58 #include <visp3/gui/vpDisplayGDI.h> 59 #include <visp3/gui/vpDisplayGTK.h> 60 #include <visp3/gui/vpDisplayOpenCV.h> 61 #include <visp3/gui/vpDisplayX.h> 62 #include <visp3/io/vpImageIo.h> 63 #include <visp3/io/vpParseArgv.h> 64 #include <visp3/io/vpVideoReader.h> 65 #include <visp3/mbt/vpMbEdgeKltMultiTracker.h> 67 #define GETOPTARGS "x:m:i:n:de:chtfColwvp" 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>] [-e <last frame index>]\n\ 77 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]\n", name);
81 -i <input image path> \n\ 82 Set image input path.\n\ 83 From this path read images \n\ 84 \"mbt/cube/image%%04d.ppm\". These \n\ 85 images come from ViSP-images-x.y.z.tar.gz available \n\ 86 on the ViSP website.\n\ 87 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 88 variable produces the same behavior than using\n\ 92 Set the config file (the xml file) to use.\n\ 93 The config file is used to specify the parameters of the tracker.\n\ 96 Specify the name of the file of the model\n\ 97 The model can either be a vrml model (.wrl) or a .cao file.\n\ 99 -e <last frame index> \n\ 100 Specify the index of the last frame. Once reached, the tracking is stopped\n\ 103 Do not use the vrml model, use the .cao one. These two models are \n\ 104 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\ 105 website. However, the .cao model allows to use the 3d model based tracker \n\ 109 Track only the cube (not the cylinder). In this case the models files are\n\ 110 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\ 111 cube_and_cylinder.wrl.\n\ 113 -n <initialisation file base name> \n\ 114 Base name of the initialisation file. The file will be 'base_name'.init .\n\ 115 This base name is also used for the optional picture specifying where to \n\ 116 click (a .ppm picture).\n\ 119 Turn off the display of the the moving edges and Klt points. \n\ 122 Turn off the display.\n\ 125 Disable the mouse click. Useful to automate the \n\ 126 execution of this program without human intervention.\n\ 129 Use Ogre3D for visibility tests\n\ 132 When Ogre3D is enable [-o] show Ogre3D configuration dialog that allows to set the renderer.\n\ 135 Use the scanline for visibility tests.\n\ 138 Compute covariance matrix.\n\ 141 Compute gradient projection error.\n\ 144 Print the help.\n\n");
147 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
150 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
151 std::string &initFile,
long &lastFrame,
bool &displayFeatures,
bool &click_allowed,
bool &display,
152 bool &cao3DModel,
bool &trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
153 bool &computeCovariance,
bool &projectionError)
161 lastFrame = atol(optarg_);
167 configFile = optarg_;
176 displayFeatures =
false;
182 click_allowed =
false;
188 trackCylinder =
false;
197 showOgreConfigDialog =
true;
200 computeCovariance =
true;
203 projectionError =
true;
206 usage(argv[0], NULL);
211 usage(argv[0], optarg_);
217 if ((c == 1) || (c == -1)) {
219 usage(argv[0], NULL);
220 std::cerr <<
"ERROR: " << std::endl;
221 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
228 int main(
int argc,
const char **argv)
231 std::string env_ipath;
232 std::string opt_ipath;
234 std::string opt_configFile;
235 std::string configFile;
236 std::string opt_modelFile;
237 std::string modelFile;
238 std::string opt_initFile;
239 std::string initFile;
240 long opt_lastFrame = -1;
241 bool displayFeatures =
true;
242 bool opt_click_allowed =
true;
243 bool opt_display =
true;
244 bool cao3DModel =
false;
245 bool trackCylinder =
true;
246 bool useOgre =
false;
247 bool showOgreConfigDialog =
false;
248 bool useScanline =
false;
249 bool computeCovariance =
false;
250 bool projectionError =
false;
258 if (!env_ipath.empty())
262 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayFeatures,
263 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
264 useScanline, computeCovariance, projectionError)) {
269 if (opt_ipath.empty() && env_ipath.empty()) {
270 usage(argv[0], NULL);
271 std::cerr << std::endl <<
"ERROR:" << std::endl;
272 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
273 <<
" environment variable to specify the location of the " << std::endl
274 <<
" image path where test images are located." << std::endl
281 if (!opt_ipath.empty())
286 if (!opt_configFile.empty())
287 configFile = opt_configFile;
288 else if (!opt_ipath.empty())
293 if (!opt_modelFile.empty()) {
294 modelFile = opt_modelFile;
296 std::string modelFileCao;
297 std::string modelFileWrl;
299 modelFileCao =
"mbt/cube_and_cylinder.cao";
300 modelFileWrl =
"mbt/cube_and_cylinder.wrl";
302 modelFileCao =
"mbt/cube.cao";
303 modelFileWrl =
"mbt/cube.wrl";
306 if (!opt_ipath.empty()) {
310 #ifdef VISP_HAVE_COIN3D 313 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
321 #ifdef VISP_HAVE_COIN3D 324 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
331 if (!opt_initFile.empty())
332 initFile = opt_initFile;
333 else if (!opt_ipath.empty())
346 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
357 #if defined VISP_HAVE_X11 359 #elif defined VISP_HAVE_GDI 361 #elif defined VISP_HAVE_OPENCV 363 #elif defined VISP_HAVE_D3D9 365 #elif defined VISP_HAVE_GTK 371 #if (defined VISP_HAVE_DISPLAY) 374 display1.
init(I1, 100, 100,
"Test tracking (Left)");
388 #if defined(VISP_HAVE_XML2) 390 tracker.loadConfigFile(configFile, configFile);
414 tracker.setCameraParameters(cam1, cam2);
415 tracker.setMovingEdge(me);
416 tracker.setKltOpencv(klt);
417 tracker.setKltMaskBorder(5);
422 tracker.setNearClippingDistance(0.01);
423 tracker.setFarClippingDistance(0.90);
431 tracker.setDisplayFeatures(displayFeatures);
434 tracker.setOgreVisibilityTest(useOgre);
436 tracker.setOgreShowConfigDialog(showOgreConfigDialog);
439 tracker.setScanLineVisibilityTest(useScanline);
442 tracker.setCovarianceComputation(computeCovariance);
445 tracker.setProjectionErrorComputation(projectionError);
448 tracker.getCameraParameters(cam1, cam2);
451 if (opt_display && opt_click_allowed) {
460 tracker.loadModel(modelFile);
468 if (opt_display && opt_click_allowed) {
469 tracker.initClick(I1, I2, initFile, initFile,
true);
470 tracker.getPose(c1Mo, c2Mo);
472 tracker.display(I1, I2, c1Mo, c2Mo, cam1, cam2,
vpColor::red);
474 vpHomogeneousMatrix c1Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
475 vpHomogeneousMatrix c2Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
476 tracker.initFromPose(I1, I2, c1Moi, c2Moi);
480 tracker.track(I1, I2);
481 tracker.getPose(c1Mo, c2Mo);
488 while (!reader.
end()) {
500 std::cout <<
"----------Test reset tracker----------" << std::endl;
505 tracker.resetTracker();
506 #if defined(VISP_HAVE_XML2) 507 tracker.loadConfigFile(configFile, configFile);
531 tracker.setCameraParameters(cam1, cam2);
532 tracker.setMovingEdge(me);
533 tracker.setKltOpencv(klt);
534 tracker.setKltMaskBorder(5);
539 tracker.setNearClippingDistance(0.01);
540 tracker.setFarClippingDistance(0.90);
546 tracker.loadModel(modelFile);
547 tracker.setCameraParameters(cam1, cam2);
548 tracker.setOgreVisibilityTest(useOgre);
549 tracker.setScanLineVisibilityTest(useScanline);
550 tracker.setCovarianceComputation(computeCovariance);
551 tracker.setProjectionErrorComputation(projectionError);
552 tracker.initFromPose(I1, I2, c1Mo, c2Mo);
557 c1Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
558 c2Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
559 std::cout <<
"Test set pose" << std::endl;
560 tracker.setPose(I1, I2, c1Mo, c2Mo);
566 tracker.track(I1, I2);
567 tracker.getPose(c1Mo, c2Mo);
577 if (opt_click_allowed) {
585 if (computeCovariance) {
586 std::cout <<
"Covariance matrix: \n" << tracker.getCovarianceMatrix() << std::endl << std::endl;
589 if (projectionError) {
590 std::cout <<
"Projection error: " << tracker.getProjectionError() << std::endl << std::endl;
597 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
599 if (opt_click_allowed && !quit) {
604 #if defined(VISP_HAVE_XML2) 610 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION == 2 || COIN_MAJOR_VERSION == 3) 619 std::cout <<
"Catch an exception: " << e << std::endl;
628 std::cout <<
"visp_mbt, visp_gui modules and OpenCV are required to run " static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setHarrisFreeParameter(double harris_k)
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 setMaxFeatures(const int maxCount)
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...
void setMinDistance(double minDistance)
error that can be emited by ViSP classes.
Hybrid stereo (or more) tracker based on moving-edges and keypoints tracked using KLT tracker...
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 setQuality(double qualityLevel)
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 setPyramidLevels(const int pyrMaxLevel)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void setMu2(const double &mu_2)
void setWindowSize(const int winSize)
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()
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
void setBlockSize(const int blockSize)
void setThreshold(const double &t)
void setRange(const unsigned int &r)
unsigned int getWidth() const