44 #include <visp3/core/vpConfig.h>
46 #if (defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY)) && \
47 (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
49 #include <visp3/core/vpDebug.h>
50 #include <visp3/core/vpHomogeneousMatrix.h>
51 #include <visp3/core/vpIoTools.h>
52 #include <visp3/core/vpMath.h>
53 #include <visp3/gui/vpDisplayD3D.h>
54 #include <visp3/gui/vpDisplayGDI.h>
55 #include <visp3/gui/vpDisplayGTK.h>
56 #include <visp3/gui/vpDisplayOpenCV.h>
57 #include <visp3/gui/vpDisplayX.h>
58 #include <visp3/io/vpImageIo.h>
59 #include <visp3/io/vpParseArgv.h>
60 #include <visp3/io/vpVideoReader.h>
61 #include <visp3/mbt/vpMbEdgeTracker.h>
63 #define GETOPTARGS "x:m:i:n:de:chtfColwvp"
65 #ifdef ENABLE_VISP_NAMESPACE
69 void usage(
const char *name,
const char *badparam)
71 #if defined(VISP_HAVE_DATASET)
72 #if VISP_HAVE_DATASET_VERSION >= 0x030600
73 std::string ext(
"png");
75 std::string ext(
"pgm");
79 std::string ext(
"png");
83 Example of tracking based on the 3D model.\n\
86 %s [-i <test image path>] [-x <config file>]\n\
87 [-m <model name>] [-n <initialisation file base name>] [-e <last frame index>]\n\
88 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]\n",
93 -i <input image path> \n\
94 Set image input path.\n\
95 From this path read images \n\
96 \"mbt/cube/image%%04d.%s\". These \n\
97 images come from visp-images-x.y.z.tar.gz available \n\
98 on the ViSP website.\n\
99 Setting the VISP_INPUT_IMAGE_PATH environment\n\
100 variable produces the same behaviour than using\n\
104 Set the config file (the xml file) to use.\n\
105 The config file is used to specify the parameters of the tracker.\n\
108 Specify the name of the file of the model\n\
109 The model can either be a vrml model (.wrl) or a .cao file.\n\
111 -e <last frame index> \n\
112 Specify the index of the last frame. Once reached, the tracking is stopped\n\
115 Do not use the vrml model, use the .cao one. These two models are \n\
116 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
117 website. However, the .cao model allows to use the 3d model based tracker \n\
121 Track only the cube (not the cylinder). In this case the models files are\n\
122 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
123 cube_and_cylinder.wrl.\n\
125 -n <initialisation file base name> \n\
126 Base name of the initialisation file. The file will be 'base_name'.init .\n\
127 This base name is also used for the Optional picture specifying where to \n\
128 click (a .ppm picture).\n\
131 Turn off the display of the the moving edges. \n\
134 Turn off the display.\n\
137 Disable the mouse click. Useful to automate the \n\
138 execution of this program without human intervention.\n\
141 Use Ogre3D for visibility tests.\n\
144 When Ogre3D is enable [-o] show Ogre3D configuration dialog thatallows to set the renderer.\n\
147 Use the scanline for visibility tests.\n\
150 Compute covariance matrix.\n\
153 Compute gradient projection error.\n\
156 Print the help.\n\n",
160 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
163 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
164 std::string &initFile,
long &lastFrame,
bool &displayFeatures,
bool &click_allowed,
bool &display,
165 bool &cao3DModel,
bool &trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
166 bool &computeCovariance,
bool &projectionError)
174 lastFrame = atol(optarg_);
180 configFile = optarg_;
189 displayFeatures =
false;
195 click_allowed =
false;
201 trackCylinder =
false;
210 showOgreConfigDialog =
true;
213 computeCovariance =
true;
216 projectionError =
true;
219 usage(argv[0],
nullptr);
224 usage(argv[0], optarg_);
230 if ((c == 1) || (c == -1)) {
232 usage(argv[0],
nullptr);
233 std::cerr <<
"ERROR: " << std::endl;
234 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
241 int main(
int argc,
const char **argv)
244 std::string env_ipath;
245 std::string opt_ipath;
247 std::string opt_configFile;
248 std::string configFile;
249 std::string opt_modelFile;
250 std::string modelFile;
251 std::string opt_initFile;
252 std::string initFile;
253 long opt_lastFrame = -1;
254 bool displayFeatures =
true;
255 bool opt_click_allowed =
true;
256 bool opt_display =
true;
257 bool cao3DModel =
false;
258 bool trackCylinder =
true;
259 bool useOgre =
false;
260 bool showOgreConfigDialog =
false;
261 bool useScanline =
false;
262 bool computeCovariance =
false;
263 bool projectionError =
false;
266 #if defined(VISP_HAVE_DATASET)
267 #if VISP_HAVE_DATASET_VERSION >= 0x030600
268 std::string ext(
"png");
270 std::string ext(
"pgm");
274 std::string ext(
"png");
282 if (!env_ipath.empty())
286 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayFeatures,
287 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
288 useScanline, computeCovariance, projectionError)) {
293 if (opt_ipath.empty() && env_ipath.empty()) {
294 usage(argv[0],
nullptr);
295 std::cerr << std::endl <<
"ERROR:" << std::endl;
296 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
297 <<
" environment variable to specify the location of the " << std::endl
298 <<
" image path where test images are located." << std::endl
305 if (!opt_ipath.empty())
310 if (!opt_configFile.empty())
311 configFile = opt_configFile;
312 else if (!opt_ipath.empty())
317 if (!opt_modelFile.empty()) {
318 modelFile = opt_modelFile;
321 std::string modelFileCao;
322 std::string modelFileWrl;
324 modelFileCao =
"mbt/cube_and_cylinder.cao";
325 modelFileWrl =
"mbt/cube_and_cylinder.wrl";
328 modelFileCao =
"mbt/cube.cao";
329 modelFileWrl =
"mbt/cube.wrl";
332 if (!opt_ipath.empty()) {
337 #ifdef VISP_HAVE_COIN3D
340 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
350 #ifdef VISP_HAVE_COIN3D
353 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
360 if (!opt_initFile.empty())
361 initFile = opt_initFile;
362 else if (!opt_ipath.empty())
375 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
385 #if defined(VISP_HAVE_X11)
387 #elif defined(VISP_HAVE_GDI)
389 #elif defined(HAVE_OPENCV_HIGHGUI)
391 #elif defined(VISP_HAVE_D3D9)
393 #elif defined(VISP_HAVE_GTK)
399 #if defined(VISP_HAVE_DISPLAY)
400 display.init(I, 100, 100,
"Test tracking");
411 #if defined(VISP_HAVE_PUGIXML)
463 if (opt_display && opt_click_allowed) {
480 if (opt_display && opt_click_allowed) {
487 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
498 while (!reader.
end()) {
512 #if defined(VISP_HAVE_PUGIXML)
551 cMo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
579 if (opt_click_allowed) {
587 if (computeCovariance) {
588 std::cout <<
"Covariance matrix: \n" << tracker.
getCovarianceMatrix() << std::endl << std::endl;
591 if (projectionError) {
592 std::cout <<
"Projection error: " << tracker.
getProjectionError() << std::endl << std::endl;
599 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
601 if (opt_click_allowed && !quit) {
609 std::cout <<
"Catch an exception: " << e << std::endl;
614 #elif !(defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_DISPLAY))
617 std::cout <<
"Cannot run this example: visp_mbt, visp_gui modules are required." << std::endl;
623 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
static const vpColor darkRed
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
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), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Make the complete tracking of an object by using its CAD model.
virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE
virtual void setNearClippingDistance(const double &dist) VP_OVERRIDE
virtual void track(const vpImage< unsigned char > &I) VP_OVERRIDE
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false) VP_OVERRIDE
virtual void setFarClippingDistance(const double &dist) VP_OVERRIDE
virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE
virtual void setClipping(const unsigned int &flags) VP_OVERRIDE
void resetTracker() VP_OVERRIDE
void setMovingEdge(const vpMe &me)
virtual void setCameraParameters(const vpCameraParameters &cam) VP_OVERRIDE
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE
virtual void loadConfigFile(const std::string &configFile, bool verbose=true) VP_OVERRIDE
virtual void setOgreShowConfigDialog(bool showConfigDialog)
virtual void getCameraParameters(vpCameraParameters &cam) const
virtual void setDisplayFeatures(bool displayF)
virtual void getPose(vpHomogeneousMatrix &cMo) const
virtual void setCovarianceComputation(const bool &flag)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual vpMatrix getCovarianceMatrix() const
virtual double getProjectionError() const
virtual void setProjectionErrorComputation(const bool &flag)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual unsigned int getClipping() const
void setMu1(const double &mu_1)
void setRange(const unsigned int &range)
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
void setMaskNumber(const unsigned int &mask_number)
void setThreshold(const double &threshold)
void setSampleStep(const double &sample_step)
void setMaskSize(const unsigned int &mask_size)
void setMu2(const double &mu_2)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void acquire(vpImage< vpRGBa > &I)
void setLastFrameIndex(const long last_frame)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
long getFirstFrameIndex()
long getFrameIndex() const