1 #include <visp3/gui/vpDisplayGDI.h>
3 #include <visp3/gui/vpDisplayOpenCV.h>
4 #include <visp3/gui/vpDisplayX.h>
5 #include <visp3/io/vpImageIo.h>
6 #include <visp3/core/vpIoTools.h>
8 #include <visp3/mbt/vpMbEdgeKltMultiTracker.h>
10 #include <visp3/io/vpVideoReader.h>
13 int main(
int argc,
char** argv)
15 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
17 std::string opt_videoname_left =
"teabox_left.mpg";
18 std::string opt_videoname_right =
"teabox_right.mpg";
21 for (
int i=0; i<argc; i++) {
22 if (std::string(argv[i]) ==
"--name" && i+2 < argc) {
23 opt_videoname_left = std::string(argv[i+1]);
24 opt_videoname_right = std::string(argv[i+2]);
25 }
else if (std::string(argv[i]) ==
"--tracker" && i+1 < argc) {
26 opt_tracker = atoi(argv[i+1]);
27 }
else if (std::string(argv[i]) ==
"--help") {
28 std::cout <<
"\nUsage: " << argv[0] <<
" [--name <video name left> <video name right>] "
29 "[--tracker <0=egde|1=klt|2=hybrid>] [--help]\n" << std::endl;
37 if(! parentname.empty()) {
38 objectname_left = parentname +
"/" + objectname_left;
41 std::cout <<
"Video name: " << opt_videoname_left <<
" ; " << opt_videoname_right << std::endl;
42 std::cout <<
"Tracker requested config files: " << objectname_left
43 <<
".[init, cao]" <<
" and " << objectname_right
44 <<
".[init, cao]" << std::endl;
45 std::cout <<
"Tracker optional config files: " << opt_videoname_left <<
".ppm"
46 <<
" and " << opt_videoname_right <<
".ppm" << std::endl;
56 g_right.
open(I_right);
58 vpDisplay *display_left = NULL, *display_right = NULL;
59 #if defined(VISP_HAVE_X11)
62 #elif defined(VISP_HAVE_GDI)
71 display_left->init(I_left, 100, 100,
"Model-based tracker (Left)");
72 display_right->init(I_right, 110 + (
int) I_left.
getWidth(), 100,
"Model-based tracker (Right)");
78 #ifdef VISP_HAVE_MODULE_KLT
79 else if (opt_tracker == 1)
85 std::cout <<
"klt and hybrid model-based tracker are not available since visp_klt module is missing" << std::endl;
93 dynamic_cast<vpMbEdgeMultiTracker*
> (tracker)->loadConfigFile(objectname_left +
".xml", objectname_right +
".xml");
94 else if(opt_tracker == 1)
95 dynamic_cast<vpMbKltMultiTracker*
> (tracker)->loadConfigFile(objectname_left +
".xml", objectname_right +
".xml");
97 dynamic_cast<vpMbEdgeKltMultiTracker*
>(tracker)->loadConfigFile(objectname_left +
".xml", objectname_right +
".xml");
104 else if(opt_tracker == 1)
118 std::ifstream file_cRightMcLeft(
"cRightMcLeft.txt");
119 cRightMcLeft.
load(file_cRightMcLeft);
122 std::map<std::string, vpHomogeneousMatrix> mapOfCameraTransformationMatrix;
124 mapOfCameraTransformationMatrix[
"Camera2"] = cRightMcLeft;
127 dynamic_cast<vpMbEdgeMultiTracker*
> (tracker)->setCameraTransformationMatrix(mapOfCameraTransformationMatrix);
128 else if(opt_tracker == 1)
129 dynamic_cast<vpMbKltMultiTracker*
> (tracker)->setCameraTransformationMatrix(mapOfCameraTransformationMatrix);
131 dynamic_cast<vpMbEdgeKltMultiTracker*
>(tracker)->setCameraTransformationMatrix(mapOfCameraTransformationMatrix);
134 #ifndef VISP_HAVE_XML2
135 std::cout <<
"\n**********************************************************\n"
136 <<
"Warning: we are not able to load the tracker settings from\n"
137 <<
"the xml config files since ViSP is not build with libxml2\n"
138 <<
"3rd party. As a consequence, the tracking may fail !"
139 <<
"\n**********************************************************\n"
145 dynamic_cast<vpMbEdgeMultiTracker*
> (tracker)->initClick(I_left, I_right, objectname_left +
".init", objectname_right +
".init",
true);
146 else if(opt_tracker == 1)
147 dynamic_cast<vpMbKltMultiTracker*
> (tracker)->initClick(I_left, I_right, objectname_left +
".init", objectname_right +
".init",
true);
149 dynamic_cast<vpMbEdgeKltMultiTracker*
>(tracker)->initClick(I_left, I_right, objectname_left +
".init", objectname_right +
".init",
true);
155 while(!g_left.
end() && !g_right.
end()) {
165 else if(opt_tracker == 1)
174 else if(opt_tracker == 1)
183 else if(opt_tracker == 1)
204 delete display_right;
209 std::cerr <<
"Catch a ViSP exception: " << e.
getMessage() << std::endl;
214 std::cout <<
"Install OpenCV and rebuild ViSP to use this example." << std::endl;
virtual void setDisplayFeatures(const bool displayF)
Class that defines generic functionnalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
unsigned int getWidth() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual void setDownScalingFactor(unsigned int scale)
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)
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...
static const vpColor none
error that can be emited by ViSP classes.
Hybrid stereo (or more) tracker based on moving-edges and keypoints tracked using KLT tracker...
static void flush(const vpImage< unsigned char > &I)
void load(std::ifstream &f)
void open(vpImage< vpRGBa > &I)
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.
Main methods for a model-based tracker.
void acquire(vpImage< vpRGBa > &I)
const char * getMessage(void) const
void setFileName(const char *filename)
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, vpImagePoint offset=vpImagePoint(0, 0))
virtual void loadModel(const char *modelFile, const bool verbose=false)
Make the complete stereo (or more) tracking of an object by using its CAD model.
Model based stereo (or more) tracker using only KLT.