46 #include <visp3/core/vpConfig.h> 48 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && \ 49 defined(VISP_HAVE_DISPLAY) && (VISP_HAVE_OPENCV_VERSION >= 0x020100) 51 #include <visp3/core/vpDebug.h> 52 #include <visp3/core/vpHomogeneousMatrix.h> 53 #include <visp3/core/vpIoTools.h> 54 #include <visp3/core/vpMath.h> 55 #include <visp3/gui/vpDisplayD3D.h> 56 #include <visp3/gui/vpDisplayGDI.h> 57 #include <visp3/gui/vpDisplayGTK.h> 58 #include <visp3/gui/vpDisplayOpenCV.h> 59 #include <visp3/gui/vpDisplayX.h> 60 #include <visp3/io/vpImageIo.h> 61 #include <visp3/io/vpParseArgv.h> 62 #include <visp3/io/vpVideoReader.h> 63 #include <visp3/mbt/vpMbKltTracker.h> 65 #define GETOPTARGS "x:m:i:n:de:chtfolwv" 67 void usage(
const char *name,
const char *badparam)
70 Example of tracking based on the 3D model.\n\ 73 %s [-i <test image path>] [-x <config file>]\n\ 74 [-m <model name>] [-n <initialisation file base name>] [-e <last frame index>]\n\ 75 [-t] [-c] [-d] [-h] [-f] [-o] [-w] [-l] [-v]\n", name);
79 -i <input image path> \n\ 80 Set image input path.\n\ 81 From this path read images \n\ 82 \"mbt/cube/image%%04d.ppm\". These \n\ 83 images come from ViSP-images-x.y.z.tar.gz available \n\ 84 on the ViSP website.\n\ 85 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 86 variable produces the same behaviour than using\n\ 90 Set the config file (the xml file) to use.\n\ 91 The config file is used to specify the parameters of the tracker.\n\ 94 Specify the name of the file of the model\n\ 95 The model can either be a vrml model (.wrl) or a .cao file.\n\ 97 -e <last frame index> \n\ 98 Specify the index of the last frame. Once reached, the tracking is stopped\n\ 101 Do not use the vrml model, use the .cao one. These two models are \n\ 102 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\ 103 website. However, the .cao model allows to use the 3d model based tracker \n\ 106 -n <initialisation file base name> \n\ 107 Base name of the initialisation file. The file will be 'base_name'.init .\n\ 108 This base name is also used for the optionnal picture specifying where to \n\ 109 click (a .ppm picture).\n\ 112 Turn off the display of the the klt points. \n\ 115 Turn off the display.\n\ 118 Disable the mouse click. Useful to automaze the \n\ 119 execution of this program without humain intervention.\n\ 122 Use Ogre3D for visibility tests\n\ 125 When Ogre3D is enable [-o] show Ogre3D configuration dialog thatallows to set the renderer.\n\ 128 Use the scanline for visibility tests.\n\ 131 Compute covariance matrix.\n\ 134 Print the help.\n\n");
137 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
140 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
141 std::string &initFile,
long &lastFrame,
bool &displayKltPoints,
bool &click_allowed,
bool &display,
142 bool &cao3DModel,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
bool &computeCovariance)
150 lastFrame = atol(optarg_);
156 configFile = optarg_;
165 displayKltPoints =
false;
171 click_allowed =
false;
183 showOgreConfigDialog =
true;
186 computeCovariance =
true;
189 usage(argv[0], NULL);
194 usage(argv[0], optarg_);
200 if ((c == 1) || (c == -1)) {
202 usage(argv[0], NULL);
203 std::cerr <<
"ERROR: " << std::endl;
204 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
211 int main(
int argc,
const char **argv)
214 std::string env_ipath;
215 std::string opt_ipath;
217 std::string opt_configFile;
218 std::string configFile;
219 std::string opt_modelFile;
220 std::string modelFile;
221 std::string opt_initFile;
222 std::string initFile;
223 long opt_lastFrame = -1;
224 bool displayKltPoints =
true;
225 bool opt_click_allowed =
true;
226 bool opt_display =
true;
227 bool cao3DModel =
false;
228 bool useOgre =
false;
229 bool showOgreConfigDialog =
false;
230 bool useScanline =
false;
231 bool computeCovariance =
false;
239 if (!env_ipath.empty())
243 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayKltPoints,
244 opt_click_allowed, opt_display, cao3DModel, useOgre, showOgreConfigDialog, useScanline,
245 computeCovariance)) {
250 if (opt_ipath.empty() && env_ipath.empty()) {
251 usage(argv[0], NULL);
252 std::cerr << std::endl <<
"ERROR:" << std::endl;
253 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
254 <<
" environment variable to specify the location of the " << std::endl
255 <<
" image path where test images are located." << std::endl
262 if (!opt_ipath.empty())
267 if (!opt_configFile.empty())
268 configFile = opt_configFile;
269 else if (!opt_ipath.empty())
274 if (!opt_modelFile.empty()) {
275 modelFile = opt_modelFile;
277 std::string modelFileCao =
"mbt/cube.cao";
278 std::string modelFileWrl =
"mbt/cube.wrl";
280 if (!opt_ipath.empty()) {
284 #ifdef VISP_HAVE_COIN3D 287 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
295 #ifdef VISP_HAVE_COIN3D 298 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
305 if (!opt_initFile.empty())
306 initFile = opt_initFile;
307 else if (!opt_ipath.empty())
319 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
329 #if defined VISP_HAVE_X11 331 #elif defined VISP_HAVE_GDI 333 #elif defined VISP_HAVE_OPENCV 335 #elif defined VISP_HAVE_D3D9 337 #elif defined VISP_HAVE_GTK 343 #if defined(VISP_HAVE_DISPLAY) 344 display.
init(I, 100, 100,
"Test tracking");
404 if (opt_display && opt_click_allowed) {
421 if (opt_display && opt_click_allowed) {
427 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
438 while (!reader.
end()) {
490 cMo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
518 if (opt_click_allowed) {
526 if (computeCovariance) {
527 std::cout <<
"Covariance matrix: \n" << tracker.
getCovarianceMatrix() << std::endl << std::endl;
534 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
536 if (opt_click_allowed && !quit) {
544 std::cout <<
"Catch an exception: " << e << std::endl;
553 std::cout <<
"visp_mbt, visp_gui modules and OpenCV are required to run " virtual void setKltOpencv(const vpKltOpencv &t)
virtual void track(const vpImage< unsigned char > &I)
virtual void setCovarianceComputation(const bool &flag)
virtual void loadConfigFile(const std::string &configFile, bool verbose=true)
void setMaxFeatures(int maxCount)
long getFrameIndex() const
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
virtual void setScanLineVisibilityTest(const bool &v)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setHarrisFreeParameter(double harris_k)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual unsigned int getClipping() const
virtual void setAngleDisappear(const double &a)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static const vpColor darkRed
Display for windows using GDI (available on any windows 32 platform).
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
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...
virtual void setOgreShowConfigDialog(bool showConfigDialog)
void setMinDistance(double minDistance)
error that can be emited by ViSP classes.
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()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void setQuality(double qualityLevel)
void open(vpImage< vpRGBa > &I)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
void setPyramidLevels(int pyrMaxLevel)
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.
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void acquire(vpImage< vpRGBa > &I)
void setWindowSize(int winSize)
virtual void setAngleAppear(const double &a)
Model based tracker using only KLT.
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
virtual void getCameraParameters(vpCameraParameters &cam) const
virtual void getPose(vpHomogeneousMatrix &cMo) const
void setLastFrameIndex(const long last_frame)
void setCameraParameters(const vpCameraParameters &cam)
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))
virtual void setOgreVisibilityTest(const bool &v)
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
void setFileName(const std::string &filename)
virtual void setClipping(const unsigned int &flags)
virtual void setFarClippingDistance(const double &dist)
void setBlockSize(int blockSize)
virtual void setDisplayFeatures(bool displayF)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
virtual void setNearClippingDistance(const double &dist)
virtual vpMatrix getCovarianceMatrix() const