43 #include <visp3/core/vpConfig.h>
45 #if defined(VISP_HAVE_MODULE_MBT) && defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && \
46 defined(VISP_HAVE_DISPLAY) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
48 #include <visp3/core/vpDebug.h>
49 #include <visp3/core/vpHomogeneousMatrix.h>
50 #include <visp3/core/vpIoTools.h>
51 #include <visp3/core/vpMath.h>
52 #include <visp3/gui/vpDisplayD3D.h>
53 #include <visp3/gui/vpDisplayGDI.h>
54 #include <visp3/gui/vpDisplayGTK.h>
55 #include <visp3/gui/vpDisplayOpenCV.h>
56 #include <visp3/gui/vpDisplayX.h>
57 #include <visp3/io/vpImageIo.h>
58 #include <visp3/io/vpParseArgv.h>
59 #include <visp3/io/vpVideoReader.h>
60 #include <visp3/mbt/vpMbKltTracker.h>
62 #define GETOPTARGS "x:m:i:n:de:chtfolwv"
64 void usage(
const char *name,
const char *badparam)
66 #if VISP_HAVE_DATASET_VERSION >= 0x030600
67 std::string ext(
"png");
69 std::string ext(
"pgm");
72 Example of tracking based on the 3D model.\n\
75 %s [-i <test image path>] [-x <config file>]\n\
76 [-m <model name>] [-n <initialisation file base name>] [-e <last frame index>]\n\
77 [-t] [-c] [-d] [-h] [-f] [-o] [-w] [-l] [-v]\n",
82 -i <input image path> \n\
83 Set image input path.\n\
84 From this path read images \n\
85 \"mbt/cube/image%%04d.%s\". These \n\
86 images come from visp-images-x.y.z.tar.gz available \n\
87 on the ViSP website.\n\
88 Setting the VISP_INPUT_IMAGE_PATH environment\n\
89 variable produces the same behaviour than using\n\
93 Set the config file (the xml file) to use.\n\
94 The config file is used to specify the parameters of the tracker.\n\
97 Specify the name of the file of the model\n\
98 The model can either be a vrml model (.wrl) or a .cao file.\n\
100 -e <last frame index> \n\
101 Specify the index of the last frame. Once reached, the tracking is stopped\n\
104 Do not use the vrml model, use the .cao one. These two models are \n\
105 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
106 website. However, the .cao model allows to use the 3d model based tracker \n\
109 -n <initialisation file base name> \n\
110 Base name of the initialisation file. The file will be 'base_name'.init .\n\
111 This base name is also used for the Optional picture specifying where to \n\
112 click (a .ppm picture).\n\
115 Turn off the display of the the klt points. \n\
118 Turn off the display.\n\
121 Disable the mouse click. Useful to automate the \n\
122 execution of this program without human intervention.\n\
125 Use Ogre3D for visibility tests\n\
128 When Ogre3D is enable [-o] show Ogre3D configuration dialog thatallows to set the renderer.\n\
131 Use the scanline for visibility tests.\n\
134 Compute covariance matrix.\n\
137 Print the help.\n\n",
141 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
144 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
145 std::string &initFile,
long &lastFrame,
bool &displayKltPoints,
bool &click_allowed,
bool &display,
146 bool &cao3DModel,
bool &useOgre,
bool &showOgreConfigDialog,
bool &useScanline,
bool &computeCovariance)
154 lastFrame = atol(optarg_);
160 configFile = optarg_;
169 displayKltPoints =
false;
175 click_allowed =
false;
187 showOgreConfigDialog =
true;
190 computeCovariance =
true;
193 usage(argv[0],
nullptr);
198 usage(argv[0], optarg_);
204 if ((c == 1) || (c == -1)) {
206 usage(argv[0],
nullptr);
207 std::cerr <<
"ERROR: " << std::endl;
208 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
215 int main(
int argc,
const char **argv)
218 std::string env_ipath;
219 std::string opt_ipath;
221 std::string opt_configFile;
222 std::string configFile;
223 std::string opt_modelFile;
224 std::string modelFile;
225 std::string opt_initFile;
226 std::string initFile;
227 long opt_lastFrame = -1;
228 bool displayKltPoints =
true;
229 bool opt_click_allowed =
true;
230 bool opt_display =
true;
231 bool cao3DModel =
false;
232 bool useOgre =
false;
233 bool showOgreConfigDialog =
false;
234 bool useScanline =
false;
235 bool computeCovariance =
false;
238 #if VISP_HAVE_DATASET_VERSION >= 0x030600
239 std::string ext(
"png");
241 std::string ext(
"pgm");
249 if (!env_ipath.empty())
253 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, opt_lastFrame, displayKltPoints,
254 opt_click_allowed, opt_display, cao3DModel, useOgre, showOgreConfigDialog, useScanline,
255 computeCovariance)) {
260 if (opt_ipath.empty() && env_ipath.empty()) {
261 usage(argv[0],
nullptr);
262 std::cerr << std::endl <<
"ERROR:" << std::endl;
263 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
264 <<
" environment variable to specify the location of the " << std::endl
265 <<
" image path where test images are located." << std::endl
272 if (!opt_ipath.empty())
277 if (!opt_configFile.empty())
278 configFile = opt_configFile;
279 else if (!opt_ipath.empty())
284 if (!opt_modelFile.empty()) {
285 modelFile = opt_modelFile;
288 std::string modelFileCao =
"mbt/cube.cao";
289 std::string modelFileWrl =
"mbt/cube.wrl";
291 if (!opt_ipath.empty()) {
296 #ifdef VISP_HAVE_COIN3D
299 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
309 #ifdef VISP_HAVE_COIN3D
312 std::cerr <<
"Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
319 if (!opt_initFile.empty())
320 initFile = opt_initFile;
321 else if (!opt_ipath.empty())
334 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
344 #if defined(VISP_HAVE_X11)
346 #elif defined(VISP_HAVE_GDI)
348 #elif defined(HAVE_OPENCV_HIGHGUI)
350 #elif defined(VISP_HAVE_D3D9)
352 #elif defined(VISP_HAVE_GTK)
358 #if defined(VISP_HAVE_DISPLAY)
359 display.init(I, 100, 100,
"Test tracking");
371 #if defined(VISP_HAVE_PUGIXML)
421 if (opt_display && opt_click_allowed) {
438 if (opt_display && opt_click_allowed) {
445 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
456 while (!reader.
end()) {
470 #if defined(VISP_HAVE_PUGIXML)
510 cMo.
buildFrom(0.0439540832, 0.0845870108, 0.5477322481, 2.179498458, 0.8611798108, -0.3491961946);
538 if (opt_click_allowed) {
546 if (computeCovariance) {
547 std::cout <<
"Covariance matrix: \n" << tracker.
getCovarianceMatrix() << std::endl << std::endl;
554 std::cout <<
"Reached last frame: " << reader.
getFrameIndex() << std::endl;
556 if (opt_click_allowed && !quit) {
565 std::cout <<
"Catch an exception: " << e << std::endl;
574 std::cout <<
"visp_mbt, visp_gui modules and OpenCV are required to run "
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
static const vpColor darkRed
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &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, const vpImagePoint &offset=vpImagePoint(0, 0), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
void setBlockSize(int blockSize)
void setQuality(double qualityLevel)
void setHarrisFreeParameter(double harris_k)
void setMaxFeatures(int maxCount)
void setMinDistance(double minDistance)
void setWindowSize(int winSize)
void setPyramidLevels(int pyrMaxLevel)
static double rad(double deg)
Model based tracker using only KLT.
virtual void setKltOpencv(const vpKltOpencv &t)
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false) vp_override
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) vp_override
virtual void setOgreVisibilityTest(const bool &v) vp_override
virtual void track(const vpImage< unsigned char > &I) vp_override
virtual void loadConfigFile(const std::string &configFile, bool verbose=true) vp_override
void setCameraParameters(const vpCameraParameters &cam) vp_override
virtual void setScanLineVisibilityTest(const bool &v) vp_override
void setKltMaskBorder(const unsigned int &e)
void resetTracker() vp_override
virtual void setOgreShowConfigDialog(bool showConfigDialog)
virtual void getCameraParameters(vpCameraParameters &cam) const
virtual void setDisplayFeatures(bool displayF)
virtual void getPose(vpHomogeneousMatrix &cMo) const
virtual void setAngleDisappear(const double &a)
virtual void setCovarianceComputation(const bool &flag)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual vpMatrix getCovarianceMatrix() const
virtual void setNearClippingDistance(const double &dist)
virtual void setFarClippingDistance(const double &dist)
virtual void setClipping(const unsigned int &flags)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setAngleAppear(const double &a)
virtual unsigned int getClipping() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void acquire(vpImage< vpRGBa > &I)
void setLastFrameIndex(const long last_frame)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
long getFirstFrameIndex()
long getFrameIndex() const
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.