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/vpMbKltMultiTracker.h> 66 #define GETOPTARGS "x:m:i:n:de:chtfolwv" 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] [-o] [-w] [-l] [-v]\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 behavior 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\ 107 -n <initialisation file base name> \n\ 108 Base name of the initialisation file. The file will be 'base_name'.init .\n\ 109 This base name is also used for the optional picture specifying where to \n\ 110 click (a .ppm picture).\n\ 113 Turn off the display of the the klt points. \n\ 116 Turn off the display.\n\ 119 Disable the mouse click. Useful to automate the \n\ 120 execution of this program without human intervention.\n\ 123 Use Ogre3D for visibility tests\n\ 126 When Ogre3D is enable [-o] show Ogre3D configuration dialog that allows to set the renderer.\n\ 129 Use the scanline for visibility tests.\n\ 132 Compute covariance matrix.\n\ 135 Print the help.\n\n");
138 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,
long &lastFrame,
bool &displayKltPoints,
bool &click_allowed,
bool &display,
143 bool &cao3DModel,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
bool &computeCovariance)
151 lastFrame = atol(optarg_);
157 configFile = optarg_;
166 displayKltPoints =
false;
172 click_allowed =
false;
184 showOgreConfigDialog =
true;
187 computeCovariance =
true;
190 usage(argv[0], NULL);
195 usage(argv[0], optarg_);
201 if ((c == 1) || (c == -1)) {
203 usage(argv[0], NULL);
204 std::cerr <<
"ERROR: " << std::endl;
205 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
212 int main(
int argc,
const char **argv)
215 std::string env_ipath;
216 std::string opt_ipath;
218 std::string opt_configFile;
219 std::string configFile;
220 std::string opt_modelFile;
221 std::string modelFile;
222 std::string opt_initFile;
223 std::string initFile;
224 long opt_lastFrame = -1;
225 bool displayKltPoints =
true;
226 bool opt_click_allowed =
true;
227 bool opt_display =
true;
228 bool cao3DModel =
false;
229 bool useOgre =
false;
230 bool showOgreConfigDialog =
false;
231 bool useScanline =
false;
232 bool computeCovariance =
false;
240 if (!env_ipath.empty())
244 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayKltPoints,
245 opt_click_allowed, opt_display, cao3DModel, useOgre, showOgreConfigDialog, useScanline,
246 computeCovariance)) {
251 if (opt_ipath.empty() && env_ipath.empty()) {
252 usage(argv[0], NULL);
253 std::cerr << std::endl <<
"ERROR:" << std::endl;
254 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
255 <<
" environment variable to specify the location of the " << std::endl
256 <<
" image path where test images are located." << std::endl
263 if (!opt_ipath.empty())
268 if (!opt_configFile.empty())
269 configFile = opt_configFile;
270 else if (!opt_ipath.empty())
275 if (!opt_modelFile.empty()) {
276 modelFile = opt_modelFile;
278 std::string modelFileCao =
"mbt/cube.cao";
279 std::string modelFileWrl =
"mbt/cube.wrl";
281 if (!opt_ipath.empty()) {
285 #ifdef VISP_HAVE_COIN3D 288 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
296 #ifdef VISP_HAVE_COIN3D 299 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
306 if (!opt_initFile.empty())
307 initFile = opt_initFile;
308 else if (!opt_ipath.empty())
321 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
332 #if defined VISP_HAVE_X11 334 #elif defined VISP_HAVE_GDI 336 #elif defined VISP_HAVE_OPENCV 338 #elif defined VISP_HAVE_D3D9 340 #elif defined VISP_HAVE_GTK 346 #if (defined VISP_HAVE_DISPLAY) 349 display1.
init(I1, 100, 100,
"Test tracking (Left)");
363 #if defined(VISP_HAVE_XML2) 365 tracker.loadConfigFile(configFile, configFile);
380 tracker.setCameraParameters(cam1, cam2);
381 tracker.setKltOpencv(klt);
382 tracker.setKltMaskBorder(5);
387 tracker.setNearClippingDistance(0.01);
388 tracker.setFarClippingDistance(0.90);
396 tracker.setDisplayFeatures(displayKltPoints);
399 tracker.setOgreVisibilityTest(useOgre);
401 tracker.setOgreShowConfigDialog(showOgreConfigDialog);
404 tracker.setScanLineVisibilityTest(useScanline);
407 tracker.setCovarianceComputation(computeCovariance);
410 tracker.getCameraParameters(cam1, cam2);
413 if (opt_display && opt_click_allowed) {
423 tracker.loadModel(modelFile);
431 if (opt_display && opt_click_allowed) {
432 tracker.initClick(I1, I2, initFile, initFile,
true);
433 tracker.getPose(c1Mo, c2Mo);
435 tracker.display(I1, I2, c1Mo, c2Mo, cam1, cam2,
vpColor::red);
437 vpHomogeneousMatrix c1Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
438 vpHomogeneousMatrix c2Moi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
439 tracker.initFromPose(I1, I2, c1Moi, c2Moi);
443 tracker.track(I1, I2);
444 tracker.getPose(c1Mo, c2Mo);
451 while (!reader.
end()) {
463 std::cout <<
"----------Test reset tracker----------" << std::endl;
468 tracker.resetTracker();
469 #if defined(VISP_HAVE_XML2) 470 tracker.loadConfigFile(configFile, configFile);
485 tracker.setCameraParameters(cam1, cam2);
486 tracker.setKltOpencv(klt);
487 tracker.setKltMaskBorder(5);
492 tracker.setNearClippingDistance(0.01);
493 tracker.setFarClippingDistance(0.90);
499 tracker.loadModel(modelFile);
500 tracker.setCameraParameters(cam1, cam2);
501 tracker.setOgreVisibilityTest(useOgre);
502 tracker.setScanLineVisibilityTest(useScanline);
503 tracker.setCovarianceComputation(computeCovariance);
504 tracker.initFromPose(I1, I2, c1Mo, c2Mo);
509 c1Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
510 c2Mo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
511 std::cout <<
"Test set pose" << std::endl;
512 tracker.setPose(I1, I2, c1Mo, c2Mo);
518 tracker.track(I1, I2);
519 tracker.getPose(c1Mo, c2Mo);
529 if (opt_click_allowed) {
537 if (computeCovariance) {
538 std::cout <<
"Covariance matrix: \n" << tracker.getCovarianceMatrix() << std::endl << std::endl;
545 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
547 if (opt_click_allowed && !quit) {
553 #if defined(VISP_HAVE_XML2) 559 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION == 2 || COIN_MAJOR_VERSION == 3) 568 std::cout <<
"Catch an exception: " << e << std::endl;
577 std::cout <<
"visp_mbt, visp_gui modules and OpenCV are required to run " VISP_EXPORT int wait(double t0, double t)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setHarrisFreeParameter(double harris_k)
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual void setDownScalingFactor(unsigned int scale)
static const vpColor darkRed
Display for windows using GDI (available on any windows 32 platform).
void setMaxFeatures(const int maxCount)
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.
static void flush(const vpImage< unsigned char > &I)
long getFirstFrameIndex()
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)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
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.
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)
void setPyramidLevels(const int pyrMaxLevel)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void setWindowSize(const int winSize)
long getFrameIndex() const
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))
unsigned int getDownScalingFactor()
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
void setBlockSize(const int blockSize)
unsigned int getWidth() const
Model based stereo (or more) tracker using only KLT.