Example of MBT KLT Tracking on an image sequence containing a cube.
#include <visp/vpConfig.h>
#include <visp/vpDebug.h>
#include <visp/vpDisplayD3D.h>
#include <visp/vpDisplayGTK.h>
#include <visp/vpDisplayGDI.h>
#include <visp/vpDisplayOpenCV.h>
#include <visp/vpDisplayX.h>
#include <visp/vpHomogeneousMatrix.h>
#include <visp/vpImageIo.h>
#include <visp/vpIoTools.h>
#include <visp/vpMath.h>
#include <visp/vpMbKltTracker.h>
#include <visp/vpVideoReader.h>
#include <visp/vpParseArgv.h>
#if defined (VISP_HAVE_OPENCV) && defined (VISP_HAVE_DISPLAY) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
#define GETOPTARGS "x:m:i:n:dchtfo"
void usage(const char *name, const char *badparam);
bool getOptions(int argc, const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
std::string &initFile, bool &displayKltPoints, bool &click_allowed, bool &display,
bool& cao3DModel, bool &useOgre);
void usage(const char *name, const char *badparam)
{
fprintf(stdout, "\n\
Example of tracking based on the 3D model.\n\
\n\
SYNOPSIS\n\
%s [-i <test image path>] [-x <config file>]\n\
[-m <model name>] [-n <initialisation file base name>]\n\
[-t] [-c] [-d] [-h] [-f]",
name );
fprintf(stdout, "\n\
OPTIONS: \n\
-i <input image path> \n\
Set image input path.\n\
From this path read images \n\
\"ViSP-images/mbt/cube/image%%04d.ppm\". These \n\
images come from ViSP-images-x.y.z.tar.gz available \n\
on the ViSP website.\n\
Setting the VISP_INPUT_IMAGE_PATH environment\n\
variable produces the same behaviour than using\n\
this option.\n\
\n\
-x <config file> \n\
Set the config file (the xml file) to use.\n\
The config file is used to specify the parameters of the tracker.\n\
\n\
-m <model name> \n\
Specify the name of the file of the model\n\
The model can either be a vrml model (.wrl) or a .cao file.\n\
\n\
-f \n\
Do not use the vrml model, use the .cao one. These two models are \n\
equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
website. However, the .cao model allows to use the 3d model based tracker \n\
without Coin.\n\
\n\
-n <initialisation file base name> \n\
Base name of the initialisation file. The file will be 'base_name'.init .\n\
This base name is also used for the optionnal picture specifying where to \n\
click (a .ppm picture).\
\n\
-t \n\
Turn off the display of the the klt points. \n\
\n\
-d \n\
Turn off the display.\n\
\n\
-c\n\
Disable the mouse click. Useful to automaze the \n\
execution of this program without humain intervention.\n\
\n\
-o\n\
Use Ogre3D for visibility tests\n\
\n\
-h \n\
Print the help.\n\n");
if (badparam)
fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
}
bool getOptions(int argc, const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile,
std::string &initFile, bool &displayKltPoints, bool &click_allowed, bool &display,
bool& cao3DModel, bool &useOgre)
{
const char *optarg_;
int c;
switch (c) {
case 'i': ipath = optarg_; break;
case 'x': configFile = optarg_; break;
case 'm': modelFile = optarg_; break;
case 'n': initFile = optarg_; break;
case 't': displayKltPoints = false; break;
case 'f': cao3DModel = true; break;
case 'c': click_allowed = false; break;
case 'd': display = false; break;
case 'o': useOgre = true; break;
case 'h': usage(argv[0], NULL); return false; break;
default:
usage(argv[0], optarg_);
return false; break;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], NULL);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
return false;
}
return true;
}
int
main(int argc, const char ** argv)
{
try {
std::string env_ipath;
std::string opt_ipath;
std::string ipath;
std::string opt_configFile;
std::string configFile;
std::string opt_modelFile;
std::string modelFile;
std::string opt_initFile;
std::string initFile;
bool displayKltPoints = true;
bool opt_click_allowed = true;
bool opt_display = true;
bool cao3DModel = false;
bool useOgre = false;
bool quit = false;
if (! env_ipath.empty())
ipath = env_ipath;
if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayKltPoints, opt_click_allowed, opt_display, cao3DModel, useOgre)) {
return (-1);
}
if (opt_ipath.empty() && env_ipath.empty() ){
usage(argv[0], NULL);
std::cerr << std::endl
<< "ERROR:" << std::endl;
std::cerr << " Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
<< std::endl
<< " environment variable to specify the location of the " << std::endl
<< " image path where test images are located." << std::endl
<< std::endl;
return (-1);
}
if (!opt_ipath.empty())
else
if (!opt_configFile.empty())
configFile = opt_configFile;
else if (!opt_ipath.empty())
else
if (!opt_modelFile.empty()){
modelFile = opt_modelFile;
}else{
std::string modelFileCao = "ViSP-images/mbt/cube.cao";
std::string modelFileWrl = "ViSP-images/mbt/cube.wrl";
if(!opt_ipath.empty()){
if(cao3DModel){
}
else{
#ifdef VISP_HAVE_COIN
#else
std::cerr << "Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
#endif
}
}
else{
if(cao3DModel){
}
else{
#ifdef VISP_HAVE_COIN
#else
std::cerr << "Coin is not detected in ViSP. Use the .cao model instead." << std::endl;
#endif
}
}
}
if (!opt_initFile.empty())
initFile = opt_initFile;
else if (!opt_ipath.empty())
else
try{
}catch(...){
std::cout << "Cannot open sequence: " << ipath << std::endl;
return -1;
}
#if defined VISP_HAVE_X11
#elif defined VISP_HAVE_GDI
#elif defined VISP_HAVE_OPENCV
#elif defined VISP_HAVE_D3D9
#elif defined VISP_HAVE_GTK
#else
opt_display = false;
#endif
if (opt_display)
{
#if (defined VISP_HAVE_DISPLAY)
display.
init(I, 100, 100,
"Test tracking") ;
#endif
}
#if defined (VISP_HAVE_XML2)
#else
#endif
if (opt_display && opt_click_allowed)
{
}
}
if (opt_display && opt_click_allowed)
{
}
else
{
vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
}
if (opt_display)
{
if (opt_display)
if (opt_display)
#if defined (VISP_HAVE_XML2)
#else
#endif
}
cMo.
buildFrom(0.04371844921, 0.08438820979, 0.5382029442, 2.200417277, 0.873535825, -0.3479076844);
if (opt_display) {
}
}
if (opt_display) {
}
}
if (opt_click_allowed) {
quit = true;
break;
}
}
}
if (opt_click_allowed && !quit) {
}
#if defined (VISP_HAVE_XML2)
#endif
#if defined(VISP_HAVE_COIN) && (COIN_MAJOR_VERSION == 3)
if(! cao3DModel)
SoDB::finish();
#endif
return 0;
}
std::cout << "Catch an exception: " << e << std::endl;
return 1;
}
}
#else
int main()
{
std::cout << "OpenCV and display are required." << std::endl;
return 0;
}
#endif