47 #include <visp3/core/vpConfig.h> 49 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && \ 50 defined(VISP_HAVE_DISPLAY) && (VISP_HAVE_OPENCV_VERSION >= 0x020100) 52 #include <visp3/core/vpDebug.h> 53 #include <visp3/core/vpHomogeneousMatrix.h> 54 #include <visp3/core/vpIoTools.h> 55 #include <visp3/core/vpMath.h> 56 #include <visp3/gui/vpDisplayD3D.h> 57 #include <visp3/gui/vpDisplayGDI.h> 58 #include <visp3/gui/vpDisplayGTK.h> 59 #include <visp3/gui/vpDisplayOpenCV.h> 60 #include <visp3/gui/vpDisplayX.h> 61 #include <visp3/io/vpImageIo.h> 62 #include <visp3/io/vpParseArgv.h> 63 #include <visp3/io/vpVideoReader.h> 64 #include <visp3/mbt/vpMbEdgeKltTracker.h> 66 #define GETOPTARGS "x:m:i:n:de:chtfColwvp" 68 void usage(
const char *name,
const char *badparam)
71 Example of tracking based on the 3D model.\n\ 74 %s [-i <test image path>] [-x <config file>]\n\ 75 [-m <model name>] [-n <initialisation file base name>] [-e <last frame index>]\n\ 76 [-t] [-c] [-d] [-h] [-f] [-C] [-o] [-w] [-l] [-v] [-p]\n", name);
80 -i <input image path> \n\ 81 Set image input path.\n\ 82 From this path read images \n\ 83 \"mbt/cube/image%%04d.ppm\". These \n\ 84 images come from ViSP-images-x.y.z.tar.gz available \n\ 85 on the ViSP website.\n\ 86 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 87 variable produces the same behaviour than using\n\ 91 Set the config file (the xml file) to use.\n\ 92 The config file is used to specify the parameters of the tracker.\n\ 95 Specify the name of the file of the model\n\ 96 The model can either be a vrml model (.wrl) or a .cao file.\n\ 98 -e <last frame index> \n\ 99 Specify the index of the last frame. Once reached, the tracking is stopped\n\ 102 Do not use the vrml model, use the .cao one. These two models are \n\ 103 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\ 104 website. However, the .cao model allows to use the 3d model based tracker \n\ 108 Track only the cube (not the cylinder). In this case the models files are\n\ 109 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\ 110 cube_and_cylinder.wrl.\n\ 112 -n <initialisation file base name> \n\ 113 Base name of the initialisation file. The file will be 'base_name'.init .\n\ 114 This base name is also used for the optionnal picture specifying where to \n\ 115 click (a .ppm picture).\n\ 118 Turn off the display of the the moving edges and Klt points. \n\ 121 Turn off the display.\n\ 124 Disable the mouse click. Useful to automaze the \n\ 125 execution of this program without humain intervention.\n\ 128 Use Ogre3D for visibility tests\n\ 131 When Ogre3D is enable [-o] show Ogre3D configuration dialog thatallows to set the renderer.\n\ 134 Use the scanline for visibility tests.\n\ 137 Compute covariance matrix.\n\ 140 Compute gradient projection error.\n\ 143 Print the help.\n\n");
146 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
149 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
150 std::string &initFile,
long &lastFrame,
bool &displayFeatures,
bool &click_allowed,
bool &display,
151 bool &cao3DModel,
bool &trackCylinder,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
152 bool &computeCovariance,
bool &projectionError)
160 lastFrame = atol(optarg_);
166 configFile = optarg_;
175 displayFeatures =
false;
181 click_allowed =
false;
187 trackCylinder =
false;
196 showOgreConfigDialog =
true;
199 computeCovariance =
true;
202 projectionError =
true;
205 usage(argv[0], NULL);
210 usage(argv[0], optarg_);
216 if ((c == 1) || (c == -1)) {
218 usage(argv[0], NULL);
219 std::cerr <<
"ERROR: " << std::endl;
220 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
227 int main(
int argc,
const char **argv)
230 std::string env_ipath;
231 std::string opt_ipath;
233 std::string opt_configFile;
234 std::string configFile;
235 std::string opt_modelFile;
236 std::string modelFile;
237 std::string opt_initFile;
238 std::string initFile;
239 long opt_lastFrame = -1;
240 bool displayFeatures =
true;
241 bool opt_click_allowed =
true;
242 bool opt_display =
true;
243 bool cao3DModel =
false;
244 bool trackCylinder =
true;
245 bool useOgre =
false;
246 bool showOgreConfigDialog =
false;
247 bool useScanline =
false;
248 bool computeCovariance =
false;
249 bool projectionError =
false;
257 if (!env_ipath.empty())
261 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayFeatures,
262 opt_click_allowed, opt_display, cao3DModel, trackCylinder, useOgre, showOgreConfigDialog,
263 useScanline, computeCovariance, projectionError)) {
268 if (opt_ipath.empty() && env_ipath.empty()) {
269 usage(argv[0], NULL);
270 std::cerr << std::endl <<
"ERROR:" << std::endl;
271 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
272 <<
" environment variable to specify the location of the " << std::endl
273 <<
" image path where test images are located." << std::endl
280 if (!opt_ipath.empty())
285 if (!opt_configFile.empty())
286 configFile = opt_configFile;
287 else if (!opt_ipath.empty())
292 if (!opt_modelFile.empty()) {
293 modelFile = opt_modelFile;
295 std::string modelFileCao;
296 std::string modelFileWrl;
298 modelFileCao =
"mbt/cube_and_cylinder.cao";
299 modelFileWrl =
"mbt/cube_and_cylinder.wrl";
301 modelFileCao =
"mbt/cube.cao";
302 modelFileWrl =
"mbt/cube.wrl";
305 if (!opt_ipath.empty()) {
309 #ifdef VISP_HAVE_COIN3D 312 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
320 #ifdef VISP_HAVE_COIN3D 323 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
330 if (!opt_initFile.empty())
331 initFile = opt_initFile;
332 else if (!opt_ipath.empty())
344 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
354 #if defined VISP_HAVE_X11 356 #elif defined VISP_HAVE_GDI 358 #elif defined VISP_HAVE_OPENCV 360 #elif defined VISP_HAVE_D3D9 362 #elif defined VISP_HAVE_GTK 368 #if defined(VISP_HAVE_DISPLAY) 369 display.
init(I, 100, 100,
"Test tracking");
380 #if defined(VISP_HAVE_XML2) 442 if (opt_display && opt_click_allowed) {
460 if (opt_display && opt_click_allowed) {
466 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
477 while (!reader.
end()) {
490 #if defined(VISP_HAVE_XML2) 540 cMo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
568 if (opt_click_allowed) {
576 if (computeCovariance) {
577 std::cout <<
"Covariance matrix: \n" << tracker.
getCovarianceMatrix() << std::endl << std::endl;
580 if (projectionError) {
581 std::cout <<
"Projection error: " << tracker.
getProjectionError() << std::endl << std::endl;
588 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
590 if (opt_click_allowed && !quit) {
595 #if defined(VISP_HAVE_XML2) 601 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION >= 2) 610 std::cout <<
"Catch an exception: " << e << std::endl;
619 std::cout <<
"visp_mbt, visp_gui modules and OpenCV are required to run " virtual void setKltOpencv(const vpKltOpencv &t)
virtual void setDisplayFeatures(const bool displayF)
virtual void setCovarianceComputation(const bool &flag)
virtual void setOgreShowConfigDialog(const bool showConfigDialog)
void setMovingEdge(const vpMe &me)
VISP_EXPORT int wait(double t0, double t)
long getFrameIndex() 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)
virtual void loadConfigFile(const std::string &configFile)
static const vpColor darkRed
Display for windows using GDI (available on any windows 32 platform).
virtual void loadModel(const std::string &modelFile, const bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
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)
void setKltMaskBorder(const unsigned int &e)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
static void flush(const vpImage< unsigned char > &I)
long getFirstFrameIndex()
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 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 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.
void setMu2(const double &mu_2)
void setWindowSize(const int winSize)
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))
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)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, const bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
void setRange(const unsigned int &r)
virtual void setNearClippingDistance(const double &dist)
virtual vpMatrix getCovarianceMatrix() const