45 #include <visp3/core/vpConfig.h>
47 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(VISP_HAVE_DISPLAY) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
49 #include <visp3/core/vpDebug.h>
50 #include <visp3/gui/vpDisplayD3D.h>
51 #include <visp3/gui/vpDisplayGTK.h>
52 #include <visp3/gui/vpDisplayGDI.h>
53 #include <visp3/gui/vpDisplayOpenCV.h>
54 #include <visp3/gui/vpDisplayX.h>
55 #include <visp3/core/vpHomogeneousMatrix.h>
56 #include <visp3/io/vpImageIo.h>
57 #include <visp3/core/vpIoTools.h>
58 #include <visp3/core/vpMath.h>
59 #include <visp3/io/vpVideoReader.h>
60 #include <visp3/io/vpParseArgv.h>
61 #include <visp3/mbt/vpMbEdgeKltTracker.h>
63 #define GETOPTARGS "x:m:i:n:dchtfColwvp"
65 void usage(
const char *name,
const char *badparam);
66 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
67 std::string &initFile,
bool &displayFeatures,
bool &click_allowed,
bool &display,
68 bool& cao3DModel,
bool& trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
69 bool &useScanline,
bool &computeCovariance,
bool &projectionError);
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>]\n\
79 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]",
84 -i <input image path> \n\
85 Set image input path.\n\
86 From this path read images \n\
87 \"ViSP-images/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 behaviour 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\
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 optionnal picture specifying where to \n\
116 click (a .ppm picture).\
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 automaze the \n\
126 execution of this program without humain intervention.\n\
129 Use Ogre3D for visibility tests\n\
132 When Ogre3D is enable [-o] show Ogre3D configuration dialog thatallows 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);
151 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
152 std::string &initFile,
bool &displayFeatures,
bool &click_allowed,
bool &display,
153 bool& cao3DModel,
bool& trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
154 bool &useScanline,
bool &computeCovariance,
bool &projectionError)
161 case 'i': ipath = optarg_;
break;
162 case 'x': configFile = optarg_;
break;
163 case 'm': modelFile = optarg_;
break;
164 case 'n': initFile = optarg_;
break;
165 case 't': displayFeatures =
false;
break;
166 case 'f': cao3DModel =
true;
break;
167 case 'c': click_allowed =
false;
break;
168 case 'd': display =
false;
break;
169 case 'C': trackCylinder =
false;
break;
170 case 'o': useOgre =
true;
break;
171 case 'l': useScanline =
true;
break;
172 case 'w': showOgreConfigDialog =
true;
break;
173 case 'v': computeCovariance =
true;
break;
174 case 'p': projectionError =
true;
break;
175 case 'h': usage(argv[0], NULL);
return false;
break;
178 usage(argv[0], optarg_);
183 if ((c == 1) || (c == -1)) {
185 usage(argv[0], NULL);
186 std::cerr <<
"ERROR: " << std::endl;
187 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
195 main(
int argc,
const char ** argv)
198 std::string env_ipath;
199 std::string opt_ipath;
201 std::string opt_configFile;
202 std::string configFile;
203 std::string opt_modelFile;
204 std::string modelFile;
205 std::string opt_initFile;
206 std::string initFile;
207 bool displayFeatures =
true;
208 bool opt_click_allowed =
true;
209 bool opt_display =
true;
210 bool cao3DModel =
false;
211 bool trackCylinder =
true;
212 bool useOgre =
false;
213 bool showOgreConfigDialog =
false;
214 bool useScanline =
false;
215 bool computeCovariance =
false;
216 bool projectionError =
false;
223 if (! env_ipath.empty())
227 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayFeatures,
228 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
229 useScanline, computeCovariance, projectionError)) {
234 if (opt_ipath.empty() && env_ipath.empty() ){
235 usage(argv[0], NULL);
236 std::cerr << std::endl
237 <<
"ERROR:" << std::endl;
238 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
240 <<
" environment variable to specify the location of the " << std::endl
241 <<
" image path where test images are located." << std::endl
248 if (!opt_ipath.empty())
253 if (!opt_configFile.empty())
254 configFile = opt_configFile;
255 else if (!opt_ipath.empty())
260 if (!opt_modelFile.empty()){
261 modelFile = opt_modelFile;
263 std::string modelFileCao;
264 std::string modelFileWrl;
266 modelFileCao =
"ViSP-images/mbt/cube_and_cylinder.cao";
267 modelFileWrl =
"ViSP-images/mbt/cube_and_cylinder.wrl";
269 modelFileCao =
"ViSP-images/mbt/cube.cao";
270 modelFileWrl =
"ViSP-images/mbt/cube.wrl";
273 if(!opt_ipath.empty()){
278 #ifdef VISP_HAVE_COIN3D
281 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
291 #ifdef VISP_HAVE_COIN3D
294 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
301 if (!opt_initFile.empty())
302 initFile = opt_initFile;
303 else if (!opt_ipath.empty())
315 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
322 #if defined VISP_HAVE_X11
324 #elif defined VISP_HAVE_GDI
326 #elif defined VISP_HAVE_OPENCV
328 #elif defined VISP_HAVE_D3D9
330 #elif defined VISP_HAVE_GTK
337 #if (defined VISP_HAVE_DISPLAY)
338 display.
init(I, 100, 100,
"Test tracking") ;
349 #if defined (VISP_HAVE_XML2)
409 if (opt_display && opt_click_allowed)
426 if (opt_display && opt_click_allowed)
435 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
446 while (!reader.
end())
460 #if defined (VISP_HAVE_XML2)
508 cMo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
535 if (opt_click_allowed) {
543 if(computeCovariance) {
544 std::cout <<
"Covariance matrix: \n" << tracker.
getCovarianceMatrix() << std::endl << std::endl;
547 if(projectionError) {
548 std::cout <<
"Projection error: " << tracker.
getProjectionError() << std::endl << std::endl;
553 if (opt_click_allowed && !quit) {
558 #if defined (VISP_HAVE_XML2)
563 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION == 3)
573 std::cout <<
"Catch an exception: " << e << std::endl;
582 std::cout <<
"visp_mbt, visp_gui modules and OpenCV are required to run this example." << std::endl;
virtual void setKltOpencv(const vpKltOpencv &t)
virtual void setDisplayFeatures(const bool displayF)
virtual void setCovarianceComputation(const bool &flag)
void setMovingEdge(const vpMe &me)
VISP_EXPORT int wait(double t0, double t)
long getFrameIndex() const
long getFirstFrameIndex() const
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
virtual void setScanLineVisibilityTest(const bool &v)
void setHarrisFreeParameter(double harris_k)
virtual unsigned int getClipping() const
virtual void setAngleDisappear(const double &a)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setMaskNumber(const unsigned int &a)
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.
virtual void setClipping(const unsigned int &flags)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
static void flush(const vpImage< unsigned char > &I)
virtual void setFarClippingDistance(const double &dist)
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 setOgreShowConfigDialog(const bool showConfigDialog)
void open(vpImage< vpRGBa > &I)
virtual void setOgreVisibilityTest(const bool &v)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
void setMaskSize(const unsigned int &a)
virtual void setProjectionErrorComputation(const bool &flag)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
virtual void track(const vpImage< unsigned char > &I)
virtual void getCameraParameters(vpCameraParameters &camera) const
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
virtual double getProjectionError() const
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)
virtual void setAngleAppear(const double &a)
void loadConfigFile(const char *configFile)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, const bool displayHelp=false)
void setPyramidLevels(const int pyrMaxLevel)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
virtual void setCameraParameters(const vpCameraParameters &cam)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Hybrid tracker based on moving-edges and keypoints tracked using KLT tracker.
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, vpImagePoint offset=vpImagePoint(0, 0))
void setMu2(const double &mu_2)
void setWindowSize(const int winSize)
void setMaskBorder(const unsigned int &e)
virtual void loadModel(const char *modelFile, const bool verbose=false)
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
virtual void getPose(vpHomogeneousMatrix &cMo_) const
void setBlockSize(const int blockSize)
void setThreshold(const double &t)
void setRange(const unsigned int &r)
virtual void setNearClippingDistance(const double &dist)
virtual vpMatrix getCovarianceMatrix() const