50 #include <visp/vpConfig.h>
51 #include <visp/vpDebug.h>
53 #include <visp/vpImageIo.h>
54 #include <visp/vpIoTools.h>
55 #include <visp/vpMath.h>
56 #include <visp/vpHomogeneousMatrix.h>
57 #include <visp/vpDisplayGTK.h>
58 #include <visp/vpDisplayX.h>
59 #include <visp/vpDisplayGDI.h>
61 #include <visp/vpMbEdgeTracker.h>
63 #include <visp/vpVideoReader.h>
64 #include <visp/vpParseArgv.h>
66 #if (defined VISP_HAVE_XML2)
68 #define GETOPTARGS "x:m:i:n:dchtfC"
71 void usage(
const char *name,
const char *badparam)
74 Example of tracking based on the 3D model.\n\
77 %s [-i <test image path>] [-x <config file>]\n\
78 [-m <model name>] [-n <initialisation file base name>]\n\
79 [-t] [-c] [-d] [-h] [-f] [-C]",
84 -i <input image path> \n\
85 Set image input path.\n\
86 From this path read images \n\
87 \"ViSP-images/mbt/cube/image%%04d.ppm\". These \n\
88 images come from ViSP-images-x.y.z.tar.gz available \n\
89 on the ViSP website.\n\
90 Setting the VISP_INPUT_IMAGE_PATH environment\n\
91 variable produces the same behaviour than using\n\
95 Set the config file (the xml file) to use.\n\
96 The config file is used to specify the parameters of the tracker.\n\
99 Specify the name of the file of the model\n\
100 The model can either be a vrml model (.wrl) or a .cao file.\n\
103 Do not use the vrml model, use the .cao one. These two models are \n\
104 equivalent and comes from ViSP-images-x.y.z.tar.gz available on the ViSP\n\
105 website. However, the .cao model allows to use the 3d model based tracker \n\
109 Track only the cube (not the cylinder). In this case the models files are\n\
110 cube.cao or cube.wrl instead of cube_and_cylinder.cao and \n\
111 cube_and_cylinder.wrl.\n\
113 -n <initialisation file base name> \n\
114 Base name of the initialisation file. The file will be 'base_name'.init .\n\
115 This base name is also used for the optionnal picture specifying where to \n\
116 click (a .ppm picture).\
119 Turn off the display of the the moving edges. \n\
122 Turn off the display.\n\
125 Disable the mouse click. Useful to automaze the \n\
126 execution of this program without humain intervention.\n\
129 Print the help.\n\n");
132 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
136 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &configFile, std::string &modelFile, std::string &initFile,
bool &displayMovingEdge,
bool &click_allowed,
bool &display,
bool& cao3DModel,
bool& trackCylinder)
143 case 'i': ipath = optarg;
break;
144 case 'x': configFile = optarg;
break;
145 case 'm': modelFile = optarg;
break;
146 case 'n': initFile = optarg;
break;
147 case 't': displayMovingEdge =
false;
break;
148 case 'f': cao3DModel =
true;
break;
149 case 'c': click_allowed =
false;
break;
150 case 'd': display =
false;
break;
151 case 'C': trackCylinder =
false;
break;
152 case 'h': usage(argv[0], NULL);
return false;
break;
155 usage(argv[0], optarg);
160 if ((c == 1) || (c == -1)) {
162 usage(argv[0], NULL);
163 std::cerr <<
"ERROR: " << std::endl;
164 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
172 main(
int argc,
const char ** argv)
174 std::string env_ipath;
175 std::string opt_ipath;
177 std::string opt_configFile;
178 std::string configFile;
179 std::string opt_modelFile;
180 std::string modelFile;
181 std::string opt_initFile;
182 std::string initFile;
183 bool displayMovingEdge =
true;
184 bool opt_click_allowed =
true;
185 bool opt_display =
true;
186 bool cao3DModel =
false;
187 bool trackCylinder =
true;
190 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
195 if (! env_ipath.empty())
200 if (!getOptions(argc, argv, opt_ipath, opt_configFile, opt_modelFile, opt_initFile, displayMovingEdge, opt_click_allowed, opt_display, cao3DModel, trackCylinder)) {
205 if (opt_ipath.empty() && env_ipath.empty() ){
206 usage(argv[0], NULL);
207 std::cerr << std::endl
208 <<
"ERROR:" << std::endl;
209 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
211 <<
" environment variable to specify the location of the " << std::endl
212 <<
" image path where test images are located." << std::endl
219 if (!opt_ipath.empty())
220 ipath = opt_ipath +
vpIoTools::path(
"/ViSP-images/mbt/cube/image%04d.pgm");
222 ipath = env_ipath +
vpIoTools::path(
"/ViSP-images/mbt/cube/image%04d.pgm");
224 if (!opt_configFile.empty())
225 configFile = opt_configFile;
226 else if (!opt_ipath.empty())
231 if (!opt_modelFile.empty()){
232 modelFile = opt_modelFile;
234 std::string modelFileCao;
235 std::string modelFileWrl;
237 modelFileCao =
"/ViSP-images/mbt/cube_and_cylinder.cao";
238 modelFileWrl =
"/ViSP-images/mbt/cube_and_cylinder.wrl";
240 modelFileCao =
"/ViSP-images/mbt/cube.cao";
241 modelFileWrl =
"/ViSP-images/mbt/cube.wrl";
244 if(!opt_ipath.empty()){
249 #ifdef VISP_HAVE_COIN
252 std::cerr <<
"Coin is not detected in ViSP. USe the .cao model instead." << std::endl;
262 #ifdef VISP_HAVE_COIN
265 std::cerr <<
"Coin is not detected in ViSP. USe the .cao model instead." << std::endl;
272 if (!opt_initFile.empty())
273 initFile = opt_initFile;
274 else if (!opt_ipath.empty())
286 std::cout <<
"Cannot open sequence: " << ipath << std::endl;
293 #if defined VISP_HAVE_X11
295 #elif defined VISP_HAVE_GDI
297 #elif defined VISP_HAVE_D3D
304 #if (defined VISP_HAVE_X11) || (defined VISP_HAVE_GDI) || (defined VISP_HAVE_D3D)
305 display.
init(I, 100, 100,
"Test tracking") ;
326 if (opt_display && opt_click_allowed)
331 "click after positioning the object",
349 if (opt_display && opt_click_allowed)
351 tracker.
initClick(I, initFile.c_str(),
true);
358 vpHomogeneousMatrix cMoi(0.02044769891, 0.1101505452, 0.5078963719, 2.063603907, 1.110231561, -0.4392789872);
400 std::cout <<
"error caught" << std::endl;
418 std::cout <<
"Libxml2 is required to read the configuration of the tracker." << std::endl;
void setDisplayMovingEdges(const bool displayMe)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void loadConfigFile(const std::string &filename)
void track(const vpImage< unsigned char > &I)
static const vpColor darkRed
Display for windows using GDI (available on any windows 32 platform).
virtual void initFromPose(const vpImage< unsigned char > &_I, const std::string &_initFile)
Define the X11 console to display images.
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
Make the complete tracking of an object by using its CAD model.
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
virtual void getCameraParameters(vpCameraParameters &_cam) const
virtual void initClick(const vpImage< unsigned char > &_I, const std::string &_initFile, const bool _displayHelp=false)
void open(vpImage< vpRGBa > &I)
Display for windows using Direct3D.
static void display(const vpImage< unsigned char > &I)
Generic class defining intrinsic camera parameters.
void acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness=1)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int l=1, const bool displayFullModel=false)
void getPose(vpHomogeneousMatrix &_cMo) const
virtual bool getClick(bool blocking=true)=0
void loadModel(const std::string &cad_name)
static const vpColor blue