48 #include <visp3/core/vpConfig.h> 50 #if (defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY)) \ 51 && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)) 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/vpMbGenericTracker.h> 67 #define GETOPTARGS "x:m:i:n:de:chtfColwvpT:" 71 void usage(
const char *name,
const char *badparam)
74 Example of tracking based on the 3D model.\n\ 77 %s [-i <test image path>] [-x <config file>]\n\ 78 [-m <model name>] [-n <initialisation file base name>] [-e <last frame index>]\n\ 79 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]\n\ 80 [-T <tracker type>]\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 and Klt points. \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 Set tracker type (<1 (Edge)>, <2 (KLT)>, <3 (EdgeKlt)>).\n\ 150 Print the help.\n\n");
153 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
156 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
157 std::string &initFile,
long &lastFrame,
bool &displayFeatures,
bool &click_allowed,
bool &display,
158 bool &cao3DModel,
bool &trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
159 bool &computeCovariance,
bool &projectionError,
int &trackerType)
167 lastFrame = atol(optarg_);
173 configFile = optarg_;
182 displayFeatures =
false;
188 click_allowed =
false;
194 trackCylinder =
false;
203 showOgreConfigDialog =
true;
206 computeCovariance =
true;
209 projectionError =
true;
212 trackerType = atoi(optarg_);
215 usage(argv[0], NULL);
220 usage(argv[0], optarg_);
226 if ((c == 1) || (c == -1)) {
228 usage(argv[0], NULL);
229 std::cerr <<
"ERROR: " << std::endl;
230 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
237 int main(
int argc,
const char **argv)
240 std::string env_ipath;
241 std::string opt_ipath;
243 std::string opt_configFile;
244 std::string opt_modelFile;
245 std::string modelFile;
246 std::string opt_initFile;
247 std::string initFile;
248 long opt_lastFrame = -1;
249 bool displayFeatures =
true;
250 bool opt_click_allowed =
true;
251 bool opt_display =
true;
252 bool cao3DModel =
false;
253 bool trackCylinder =
true;
254 bool useOgre =
false;
255 bool showOgreConfigDialog =
false;
256 bool useScanline =
false;
257 bool computeCovariance =
false;
258 bool projectionError =
false;
266 if (!env_ipath.empty())
270 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayFeatures,
271 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
272 useScanline, computeCovariance, projectionError, trackerType)) {
277 if (opt_ipath.empty() && env_ipath.empty()) {
278 usage(argv[0], NULL);
279 std::cerr << std::endl <<
"ERROR:" << std::endl;
280 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
281 <<
" environment variable to specify the location of the " << std::endl
282 <<
" image path where test images are located." << std::endl
289 if (!opt_ipath.empty())
295 std::string configFile;
296 if (!opt_configFile.empty())
297 configFile = opt_configFile;
298 else if (!opt_ipath.empty())
304 if (!opt_modelFile.empty()) {
305 modelFile = opt_modelFile;
307 std::string modelFileCao;
308 std::string modelFileWrl;
310 modelFileCao =
"mbt/cube_and_cylinder.cao";
311 modelFileWrl =
"mbt/cube_and_cylinder.wrl";
313 modelFileCao =
"mbt/cube.cao";
314 modelFileWrl =
"mbt/cube.wrl";
317 if (!opt_ipath.empty()) {
321 #ifdef VISP_HAVE_COIN3D 324 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
332 #ifdef VISP_HAVE_COIN3D 335 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
342 if (!opt_initFile.empty())
343 initFile = opt_initFile;
344 else if (!opt_ipath.empty())
349 std::map<std::string, const vpImage<unsigned char> *> mapOfImages;
359 std::cerr <<
"Cannot open sequence: " << ipath << std::endl;
370 mapOfImages[
"Camera1"] = &I1;
371 mapOfImages[
"Camera2"] = &I2;
372 mapOfImages[
"Camera3"] = &I3;
375 #if defined VISP_HAVE_X11 377 #elif defined VISP_HAVE_GDI 379 #elif defined VISP_HAVE_OPENCV 381 #elif defined VISP_HAVE_D3D9 383 #elif defined VISP_HAVE_GTK 390 #if defined(VISP_HAVE_DISPLAY) 395 display1.
init(I1, 100, 100,
"Test tracking (Cam1)");
410 std::map<std::string, vpHomogeneousMatrix> mapOfCameraPoses;
411 std::map<std::string, vpCameraParameters> mapOfCameraParams;
416 std::map<std::string, std::string> mapOfConfigFiles;
417 mapOfConfigFiles[
"Camera1"] = configFile;
418 mapOfConfigFiles[
"Camera2"] = configFile;
419 mapOfConfigFiles[
"Camera3"] = configFile;
425 mapOfCameraParams[
"Camera1"] = cam;
426 mapOfCameraParams[
"Camera2"] = cam;
427 mapOfCameraParams[
"Camera3"] = cam;
437 std::map<std::string, vpMe> mapOfMe;
438 mapOfMe[
"Camera1"] = me;
439 mapOfMe[
"Camera2"] = me;
440 mapOfMe[
"Camera3"] = me;
442 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)) 451 std::map<std::string, vpKltOpencv> mapOfKlt;
452 mapOfKlt[
"Camera1"] = klt;
453 mapOfKlt[
"Camera2"] = klt;
454 mapOfKlt[
"Camera3"] = klt;
469 std::map<std::string, unsigned int> mapOfClippingFlags;
471 for (std::map<std::string, unsigned int>::iterator it = mapOfClippingFlags.begin(); it != mapOfClippingFlags.end();
503 if (opt_display && opt_click_allowed) {
520 if (opt_display && opt_click_allowed) {
521 std::map<std::string, std::string> mapOfInitFiles;
522 mapOfInitFiles[
"Camera1"] = initFile;
524 dynamic_cast<vpMbGenericTracker *
>(tracker)->initClick(mapOfImages, mapOfInitFiles,
true);
528 dynamic_cast<vpMbGenericTracker *
>(tracker)->display(mapOfImages, mapOfCameraPoses, mapOfCameraParams,
531 vpHomogeneousMatrix c1Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
532 std::map<std::string, vpHomogeneousMatrix> mapOfInitPoses;
533 mapOfInitPoses[
"Camera1"] = c1Moi;
535 dynamic_cast<vpMbGenericTracker *
>(tracker)->initFromPose(mapOfImages, mapOfInitPoses);
548 bool quit =
false, click =
false;
549 while (!reader.
end() && !quit) {
554 mapOfImages[
"Camera1"] = &I1;
555 mapOfImages[
"Camera2"] = &I2;
556 mapOfImages[
"Camera3"] = &I3;
564 std::stringstream ss;
571 std::cout <<
"----------Test reset tracker----------" << std::endl;
584 mapOfCameraParams[
"Camera1"] = cam;
585 mapOfCameraParams[
"Camera2"] = cam;
586 mapOfCameraParams[
"Camera3"] = cam;
596 mapOfMe[
"Camera1"] = me;
597 mapOfMe[
"Camera2"] = me;
598 mapOfMe[
"Camera3"] = me;
600 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)) 609 mapOfKlt[
"Camera1"] = klt;
610 mapOfKlt[
"Camera2"] = klt;
611 mapOfKlt[
"Camera3"] = klt;
627 for (std::map<std::string, unsigned int>::iterator it = mapOfClippingFlags.begin();
628 it != mapOfClippingFlags.end(); ++it) {
643 dynamic_cast<vpMbGenericTracker *
>(tracker)->initFromPose(mapOfImages, mapOfCameraPoses);
649 c1Moi.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
650 std::map<std::string, vpHomogeneousMatrix> mapOfSetPoses;
651 mapOfSetPoses[
"Camera1"] = c1Moi;
653 std::cout <<
"Test set pose" << std::endl;
665 std::map<std::string, const vpImage<unsigned char> *> mapOfSubImages;
666 mapOfSubImages[
"Camera1"] = &I1;
667 mapOfSubImages[
"Camera2"] = &I2;
669 dynamic_cast<vpMbGenericTracker *
>(tracker)->display(mapOfSubImages, mapOfCameraPoses, mapOfCameraParams,
672 dynamic_cast<vpMbGenericTracker *
>(tracker)->display(mapOfImages, mapOfCameraPoses, mapOfCameraParams,
682 if (opt_click_allowed && opt_display) {
701 if (computeCovariance) {
702 std::cout <<
"Covariance matrix: \n" << tracker->
getCovarianceMatrix() << std::endl << std::endl;
705 if (projectionError) {
706 std::cout <<
"Projection error: " << tracker->
getProjectionError() << std::endl << std::endl;
716 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
717 std::cout <<
"\nFinal poses, c1Mo:\n" 718 << mapOfCameraPoses[
"Camera1"] <<
"\nc2Mo:\n" 719 << mapOfCameraPoses[
"Camera2"] <<
"\nc3Mo:\n" 720 << mapOfCameraPoses[
"Camera3"] << std::endl;
722 if (opt_click_allowed && !quit) {
732 std::cout <<
"Catch an exception: " << e << std::endl;
737 #elif !(defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY)) 740 std::cout <<
"Cannot run this example: visp_mbt, visp_gui modules are required." 747 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
virtual void setCovarianceComputation(const bool &flag)
void setMaxFeatures(int maxCount)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setHarrisFreeParameter(double harris_k)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setAngleDisappear(const double &a)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setMaskNumber(const unsigned int &a)
virtual void setDownScalingFactor(unsigned int scale)
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...
virtual void setOgreShowConfigDialog(bool showConfigDialog)
virtual double getProjectionError() const
void setMinDistance(double minDistance)
error that can be emited by ViSP classes.
Real-time 6D object pose tracking using its CAD model.
virtual void resetTracker()=0
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 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)
void setPyramidLevels(int pyrMaxLevel)
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.
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
Main methods for a model-based tracker.
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void acquire(vpImage< vpRGBa > &I)
void setWindowSize(int winSize)
virtual void setAngleAppear(const double &a)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
void setMu2(const double &mu_2)
long getFrameIndex() const
virtual void setOgreVisibilityTest(const bool &v)
void setLastFrameIndex(const long last_frame)
unsigned int getHeight() const
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()
virtual vpMatrix getCovarianceMatrix() const
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
void setThreshold(const double &t)
void setFileName(const std::string &filename)
virtual void setScanLineVisibilityTest(const bool &v)
void setRange(const unsigned int &r)
virtual void setFarClippingDistance(const double &dist)
unsigned int getWidth() const
void setBlockSize(int blockSize)
virtual void setDisplayFeatures(bool displayF)
virtual void setProjectionErrorComputation(const bool &flag)
virtual void setNearClippingDistance(const double &dist)