3 #include <visp3/core/vpConfig.h> 4 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) 6 #include <visp3/core/vpIoTools.h> 7 #include <visp3/gui/vpDisplayGDI.h> 8 #include <visp3/gui/vpDisplayOpenCV.h> 9 #include <visp3/gui/vpDisplayX.h> 10 #include <visp3/io/vpImageIo.h> 12 #include <visp3/mbt/vpMbEdgeKltMultiTracker.h> 13 #include <visp3/mbt/vpMbEdgeMultiTracker.h> 15 #include <visp3/io/vpVideoReader.h> 17 int main(
int argc,
char **argv)
19 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100) 21 std::string opt_videoname_left =
"teabox_left.mpg";
22 std::string opt_videoname_right =
"teabox_right.mpg";
25 for (
int i = 0; i < argc; i++) {
26 if (std::string(argv[i]) ==
"--name" && i + 2 < argc) {
27 opt_videoname_left = std::string(argv[i + 1]);
28 opt_videoname_right = std::string(argv[i + 2]);
29 }
else if (std::string(argv[i]) ==
"--tracker" && i + 1 < argc) {
30 opt_tracker = atoi(argv[i + 1]);
31 }
else if (std::string(argv[i]) ==
"--help") {
32 std::cout <<
"\nUsage: " << argv[0]
33 <<
" [--name <video name left> <video name right>] " 34 "[--tracker <0=egde|1=klt|2=hybrid>] [--help]\n" 43 if (!parentname.empty()) {
44 objectname_left = parentname +
"/" + objectname_left;
47 std::cout <<
"Video name: " << opt_videoname_left <<
" ; " << opt_videoname_right << std::endl;
48 std::cout <<
"Tracker requested config files: " << objectname_left <<
".[init, cao]" 49 <<
" and " << objectname_right <<
".[init, cao]" << std::endl;
50 std::cout <<
"Tracker optional config files: " << opt_videoname_left <<
".ppm" 51 <<
" and " << opt_videoname_right <<
".ppm" << std::endl;
61 g_right.
open(I_right);
63 vpDisplay *display_left = NULL, *display_right = NULL;
64 #if defined(VISP_HAVE_X11) 67 #elif defined(VISP_HAVE_GDI) 76 display_left->init(I_left, 100, 100,
"Model-based tracker (Left)");
77 display_right->init(I_right, 110 + (
int)I_left.
getWidth(), 100,
"Model-based tracker (Right)");
83 #ifdef VISP_HAVE_MODULE_KLT 84 else if (opt_tracker == 1)
90 std::cout <<
"klt and hybrid model-based tracker are not available " 91 "since visp_klt module is missing" 101 objectname_right +
".xml");
102 #if defined(VISP_HAVE_MODULE_KLT) 103 else if (opt_tracker == 1)
104 dynamic_cast<vpMbKltMultiTracker *
>(tracker)->loadConfigFile(objectname_left +
".xml", objectname_right +
".xml");
107 objectname_right +
".xml");
113 if (opt_tracker == 0)
115 #if defined(VISP_HAVE_MODULE_KLT) 116 else if (opt_tracker == 1)
131 std::ifstream file_cRightMcLeft(
"cRightMcLeft.txt");
132 cRightMcLeft.
load(file_cRightMcLeft);
135 std::map<std::string, vpHomogeneousMatrix> mapOfCameraTransformationMatrix;
137 mapOfCameraTransformationMatrix[
"Camera2"] = cRightMcLeft;
139 if (opt_tracker == 0)
140 dynamic_cast<vpMbEdgeMultiTracker *
>(tracker)->setCameraTransformationMatrix(mapOfCameraTransformationMatrix);
141 #if defined(VISP_HAVE_MODULE_KLT) 142 else if (opt_tracker == 1)
143 dynamic_cast<vpMbKltMultiTracker *
>(tracker)->setCameraTransformationMatrix(mapOfCameraTransformationMatrix);
145 dynamic_cast<vpMbEdgeKltMultiTracker *
>(tracker)->setCameraTransformationMatrix(mapOfCameraTransformationMatrix);
149 #ifndef VISP_HAVE_XML2 150 std::cout <<
"\n**********************************************************\n" 151 <<
"Warning: we are not able to load the tracker settings from\n" 152 <<
"the xml config files since ViSP is not build with libxml2\n" 153 <<
"3rd party. As a consequence, the tracking may fail !" 154 <<
"\n**********************************************************\n" 159 if (opt_tracker == 0)
160 dynamic_cast<vpMbEdgeMultiTracker *
>(tracker)->initClick(I_left, I_right, objectname_left +
".init",
161 objectname_right +
".init",
true);
162 #if defined(VISP_HAVE_MODULE_KLT) 163 else if (opt_tracker == 1)
164 dynamic_cast<vpMbKltMultiTracker *
>(tracker)->initClick(I_left, I_right, objectname_left +
".init",
165 objectname_right +
".init",
true);
168 objectname_right +
".init",
true);
175 while (!g_left.
end() && !g_right.
end()) {
183 if (opt_tracker == 0)
185 #if defined(VISP_HAVE_MODULE_KLT) 186 else if (opt_tracker == 1)
194 if (opt_tracker == 0)
196 #if defined(VISP_HAVE_MODULE_KLT) 197 else if (opt_tracker == 1)
205 if (opt_tracker == 0)
206 dynamic_cast<vpMbEdgeMultiTracker *
>(tracker)->display(I_left, I_right, cLeftMo, cRightMo, cam_left, cam_right,
208 #if defined(VISP_HAVE_MODULE_KLT) 209 else if (opt_tracker == 1)
210 dynamic_cast<vpMbKltMultiTracker *
>(tracker)->display(I_left, I_right, cLeftMo, cRightMo, cam_left, cam_right,
233 delete display_right;
237 std::cerr <<
"Catch a ViSP exception: " << e.
getMessage() << std::endl;
242 std::cout <<
"Install OpenCV and rebuild ViSP to use this example." << std::endl;
248 std::cout <<
"Nothing to run, deprecated tutorial." << std::endl;
251 #endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) 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).
virtual void loadModel(const std::string &modelFile, const bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
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, const vpImagePoint &offset=vpImagePoint(0, 0))
Make the complete stereo (or more) tracking of an object by using its CAD model.
Model based stereo (or more) tracker using only KLT.