1 #include <visp3/core/vpIoTools.h> 3 #include <visp3/gui/vpDisplayGDI.h> 4 #include <visp3/gui/vpDisplayOpenCV.h> 5 #include <visp3/gui/vpDisplayX.h> 6 #include <visp3/io/vpImageIo.h> 8 #include <visp3/mbt/vpMbEdgeKltMultiTracker.h> 9 #include <visp3/mbt/vpMbEdgeMultiTracker.h> 11 #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]
29 <<
" [--name <video name left> <video name right>] " 30 "[--tracker <0=egde|1=klt|2=hybrid>] [--help]\n" 39 if (!parentname.empty()) {
40 objectname_left = parentname +
"/" + objectname_left;
43 std::cout <<
"Video name: " << opt_videoname_left <<
" ; " << opt_videoname_right << std::endl;
44 std::cout <<
"Tracker requested config files: " << objectname_left <<
".[init, cao]" 45 <<
" and " << objectname_right <<
".[init, cao]" << std::endl;
46 std::cout <<
"Tracker optional config files: " << opt_videoname_left <<
".ppm" 47 <<
" and " << opt_videoname_right <<
".ppm" << std::endl;
57 g_right.
open(I_right);
59 vpDisplay *display_left = NULL, *display_right = NULL;
60 #if defined(VISP_HAVE_X11) 63 #elif defined(VISP_HAVE_GDI) 72 display_left->init(I_left, 100, 100,
"Model-based tracker (Left)");
73 display_right->init(I_right, 110 + (
int)I_left.
getWidth(), 100,
"Model-based tracker (Right)");
79 #ifdef VISP_HAVE_MODULE_KLT 80 else if (opt_tracker == 1)
86 std::cout <<
"klt and hybrid model-based tracker are not available " 87 "since visp_klt module is missing" 97 objectname_right +
".xml");
98 #if defined(VISP_HAVE_MODULE_KLT) 99 else if (opt_tracker == 1)
100 dynamic_cast<vpMbKltMultiTracker *
>(tracker)->loadConfigFile(objectname_left +
".xml", objectname_right +
".xml");
103 objectname_right +
".xml");
109 if (opt_tracker == 0)
111 #if defined(VISP_HAVE_MODULE_KLT) 112 else if (opt_tracker == 1)
127 std::ifstream file_cRightMcLeft(
"cRightMcLeft.txt");
128 cRightMcLeft.
load(file_cRightMcLeft);
131 std::map<std::string, vpHomogeneousMatrix> mapOfCameraTransformationMatrix;
133 mapOfCameraTransformationMatrix[
"Camera2"] = cRightMcLeft;
135 if (opt_tracker == 0)
136 dynamic_cast<vpMbEdgeMultiTracker *
>(tracker)->setCameraTransformationMatrix(mapOfCameraTransformationMatrix);
137 #if defined(VISP_HAVE_MODULE_KLT) 138 else if (opt_tracker == 1)
139 dynamic_cast<vpMbKltMultiTracker *
>(tracker)->setCameraTransformationMatrix(mapOfCameraTransformationMatrix);
141 dynamic_cast<vpMbEdgeKltMultiTracker *
>(tracker)->setCameraTransformationMatrix(mapOfCameraTransformationMatrix);
145 #ifndef VISP_HAVE_XML2 146 std::cout <<
"\n**********************************************************\n" 147 <<
"Warning: we are not able to load the tracker settings from\n" 148 <<
"the xml config files since ViSP is not build with libxml2\n" 149 <<
"3rd party. As a consequence, the tracking may fail !" 150 <<
"\n**********************************************************\n" 155 if (opt_tracker == 0)
156 dynamic_cast<vpMbEdgeMultiTracker *
>(tracker)->initClick(I_left, I_right, objectname_left +
".init",
157 objectname_right +
".init",
true);
158 #if defined(VISP_HAVE_MODULE_KLT) 159 else if (opt_tracker == 1)
160 dynamic_cast<vpMbKltMultiTracker *
>(tracker)->initClick(I_left, I_right, objectname_left +
".init",
161 objectname_right +
".init",
true);
164 objectname_right +
".init",
true);
171 while (!g_left.
end() && !g_right.
end()) {
179 if (opt_tracker == 0)
181 #if defined(VISP_HAVE_MODULE_KLT) 182 else if (opt_tracker == 1)
190 if (opt_tracker == 0)
192 #if defined(VISP_HAVE_MODULE_KLT) 193 else if (opt_tracker == 1)
201 if (opt_tracker == 0)
202 dynamic_cast<vpMbEdgeMultiTracker *
>(tracker)->display(I_left, I_right, cLeftMo, cRightMo, cam_left, cam_right,
204 #if defined(VISP_HAVE_MODULE_KLT) 205 else if (opt_tracker == 1)
206 dynamic_cast<vpMbKltMultiTracker *
>(tracker)->display(I_left, I_right, cLeftMo, cRightMo, cam_left, cam_right,
229 delete display_right;
233 std::cerr <<
"Catch a ViSP exception: " << e.
getMessage() << std::endl;
238 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)
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)
void setFileName(const char *filename)
const char * getMessage(void) const
virtual void loadModel(const char *modelFile, const bool verbose=false)
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))
unsigned int getWidth() const
Make the complete stereo (or more) tracking of an object by using its CAD model.
Model based stereo (or more) tracker using only KLT.