48 #include <visp/vpConfig.h>
49 #include <visp/vpDebug.h>
50 #include <visp/vpDisplayD3D.h>
51 #include <visp/vpDisplayGTK.h>
52 #include <visp/vpDisplayGDI.h>
53 #include <visp/vpDisplayOpenCV.h>
54 #include <visp/vpDisplayX.h>
55 #include <visp/vpHomogeneousMatrix.h>
56 #include <visp/vpImageIo.h>
57 #include <visp/vpIoTools.h>
58 #include <visp/vpMath.h>
59 #include <visp/vpMbEdgeKltTracker.h>
60 #include <visp/vpVideoReader.h>
61 #include <visp/vpParseArgv.h>
63 #if defined (VISP_HAVE_OPENCV) && defined (VISP_HAVE_DISPLAY) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
66 #define GETOPTARGS "x:m:i:n:dchtfCo"
68 void usage(
const char *name,
const char *badparam);
69 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
70 std::string &initFile,
bool &displayFeatures,
bool &click_allowed,
bool &display,
71 bool& cao3DModel,
bool& trackCylinder,
bool &useOgre);
73 void usage(
const char *name,
const char *badparam)
76 Example of tracking based on the 3D model.\n\
79 %s [-i <test image path>] [-x <config file>]\n\
80 [-m <model name>] [-n <initialisation file base name>]\n\
81 [-t] [-c] [-d] [-h] [-f] [-C]",
86 -i <input image path> \n\
87 Set image input path.\n\
88 From this path read images \n\
89 \"ViSP-images/mbt/cube/image%%04d.ppm\". These \n\
90 images come from ViSP-images-x.y.z.tar.gz available \n\
91 on the ViSP website.\n\
92 Setting the VISP_INPUT_IMAGE_PATH environment\n\
93 variable produces the same behaviour than using\n\
97 Set the config file (the xml file) to use.\n\
98 The config file is used to specify the parameters of the tracker.\n\
101 Specify the name of the file of the model\n\
102 The model can either be a vrml model (.wrl) or a .cao file.\n\
105 Do not use the vrml model, use the .cao one. These two models are \n\
106 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
107 website. However, the .cao model allows to use the 3d model based tracker \n\
111 Track only the cube (not the cylinder). In this case the models files are\n\
112 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
113 cube_and_cylinder.wrl.\n\
115 -n <initialisation file base name> \n\
116 Base name of the initialisation file. The file will be 'base_name'.init .\n\
117 This base name is also used for the optionnal picture specifying where to \n\
118 click (a .ppm picture).\
121 Turn off the display of the the moving edges and Klt points. \n\
124 Turn off the display.\n\
127 Disable the mouse click. Useful to automaze the \n\
128 execution of this program without humain intervention.\n\
131 Use Ogre3D for visibility tests\n\
134 Print the help.\n\n");
137 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
141 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
142 std::string &initFile,
bool &displayFeatures,
bool &click_allowed,
bool &display,
143 bool& cao3DModel,
bool& trackCylinder,
bool &useOgre)
150 case 'i': ipath = optarg_;
break;
151 case 'x': configFile = optarg_;
break;
152 case 'm': modelFile = optarg_;
break;
153 case 'n': initFile = optarg_;
break;
154 case 't': displayFeatures =
false;
break;
155 case 'f': cao3DModel =
true;
break;
156 case 'c': click_allowed =
false;
break;
157 case 'd': display =
false;
break;
158 case 'C': trackCylinder =
false;
break;
159 case 'o' : useOgre =
true;
break;
160 case 'h': usage(argv[0], NULL);
return false;
break;
163 usage(argv[0], optarg_);
168 if ((c == 1) || (c == -1)) {
170 usage(argv[0], NULL);
171 std::cerr <<
"ERROR: " << std::endl;
172 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
180 main(
int argc,
const char ** argv)
183 std::string env_ipath;
184 std::string opt_ipath;
186 std::string opt_configFile;
187 std::string configFile;
188 std::string opt_modelFile;
189 std::string modelFile;
190 std::string opt_initFile;
191 std::string initFile;
192 bool displayFeatures =
true;
193 bool opt_click_allowed =
true;
194 bool opt_display =
true;
195 bool cao3DModel =
false;
196 bool trackCylinder =
true;
197 bool useOgre =
false;
204 if (! env_ipath.empty())
208 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayFeatures, opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre)) {
213 if (opt_ipath.empty() && env_ipath.empty() ){
214 usage(argv[0], NULL);
215 std::cerr << std::endl
216 <<
"ERROR:" << std::endl;
217 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
219 <<
" environment variable to specify the location of the " << std::endl
220 <<
" image path where test images are located." << std::endl
227 if (!opt_ipath.empty())
232 if (!opt_configFile.empty())
233 configFile = opt_configFile;
234 else if (!opt_ipath.empty())
239 if (!opt_modelFile.empty()){
240 modelFile = opt_modelFile;
242 std::string modelFileCao;
243 std::string modelFileWrl;
245 modelFileCao =
"ViSP-images/mbt/cube_and_cylinder.cao";
246 modelFileWrl =
"ViSP-images/mbt/cube_and_cylinder.wrl";
248 modelFileCao =
"ViSP-images/mbt/cube.cao";
249 modelFileWrl =
"ViSP-images/mbt/cube.wrl";
252 if(!opt_ipath.empty()){
257 #ifdef VISP_HAVE_COIN
260 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
270 #ifdef VISP_HAVE_COIN
273 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
280 if (!opt_initFile.empty())
281 initFile = opt_initFile;
282 else if (!opt_ipath.empty())
294 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
301 #if defined VISP_HAVE_X11
303 #elif defined VISP_HAVE_GDI
305 #elif defined VISP_HAVE_OPENCV
307 #elif defined VISP_HAVE_D3D9
309 #elif defined VISP_HAVE_GTK
316 #if (defined VISP_HAVE_DISPLAY)
317 display.
init(I, 100, 100,
"Test tracking") ;
328 #if defined (VISP_HAVE_XML2)
378 if (opt_display && opt_click_allowed)
394 if (opt_display && opt_click_allowed)
403 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
417 while (!reader.
end())
431 #if defined (VISP_HAVE_XML2)
477 cMo.
buildFrom(0.04371844921, 0.08438820979, 0.5382029442, 2.200417277, 0.873535825, -0.3479076844);
504 if (opt_click_allowed) {
518 if (opt_click_allowed && !quit) {
523 #if defined (VISP_HAVE_XML2)
528 #if defined(VISP_HAVE_COIN) && (COIN_MAJOR_VERSION == 3)
538 std::cout <<
"Catch an exception: " << e << std::endl;
547 std::cout <<
"OpenCV and display are required." << std::endl;
void setKltOpencv(const vpKltOpencv &t)
void setMovingEdge(const vpMe &me)
long getFrameIndex() const
long getFirstFrameIndex() const
void setHarrisFreeParameter(double harris_k)
virtual unsigned int getClipping() const
virtual void setAngleDisappear(const double &a)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
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)
void setNbTotalSample(const int &nb)
Define the X11 console to display images.
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.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Contains predetermined masks for sites and holds moving edges tracking parameters.
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 open(vpImage< vpRGBa > &I)
virtual void setOgreVisibilityTest(const bool &v)
Display for windows using Direct3D.
void setMaskSize(const unsigned int &a)
void getPose(vpHomogeneousMatrix &cMo_) const
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
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)
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void acquire(vpImage< vpRGBa > &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)
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)
Construction from translation vector and rotation matrix.
static double rad(double deg)
virtual void setCameraParameters(const vpCameraParameters &cam)
Hybrid tracker based on moving-edges and keypoints tracked using KLT tracker.
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.
void setBlockSize(const int blockSize)
void setThreshold(const double &t)
virtual bool getClick(bool blocking=true)=0
void setDisplayFeatures(const bool displayF)
void setRange(const unsigned int &r)
virtual void setNearClippingDistance(const double &dist)