3 #include <visp3/core/vpConfig.h> 4 #include <visp3/core/vpIoTools.h> 5 #include <visp3/gui/vpDisplayGDI.h> 6 #include <visp3/gui/vpDisplayOpenCV.h> 7 #include <visp3/gui/vpDisplayX.h> 8 #include <visp3/io/vpImageIo.h> 10 #include <visp3/mbt/vpMbGenericTracker.h> 12 #include <visp3/io/vpVideoReader.h> 14 int main(
int argc,
char **argv)
16 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020300) 18 std::string opt_videoname_left =
"teabox_left.mp4";
19 std::string opt_videoname_right =
"teabox_right.mp4";
23 for (
int i = 0; i < argc; i++) {
24 if (std::string(argv[i]) ==
"--name" && i + 2 < argc) {
25 opt_videoname_left = std::string(argv[i + 1]);
26 opt_videoname_right = std::string(argv[i + 2]);
27 }
else if (std::string(argv[i]) ==
"--tracker" && i + 2 < argc) {
28 opt_tracker1 = atoi(argv[i + 1]);
29 opt_tracker2 = atoi(argv[i + 2]);
30 }
else if (std::string(argv[i]) ==
"--help") {
31 std::cout <<
"\nUsage: " << argv[0]
32 <<
" [--name <video name left> <video name right>]" 33 " [--tracker <1=egde|2=klt|3=hybrid> <1=egde|2=klt|3=hybrid>]" 40 if ((opt_tracker1 < 1 || opt_tracker1 > 3) && (opt_tracker2 < 1 || opt_tracker2 > 3)) {
41 std::cerr <<
"Wrong tracker type. Correct values are: " 42 "1=egde|2=keypoint|3=hybrid." 51 if (!parentname.empty()) {
52 objectname_left = parentname +
"/" + objectname_left;
55 std::cout <<
"Video name: " << opt_videoname_left <<
" ; " << opt_videoname_right << std::endl;
56 std::cout <<
"Tracker requested config files: " << objectname_left <<
".[init, cao]" 57 <<
" and " << objectname_right <<
".[init, cao]" << std::endl;
58 std::cout <<
"Tracker optional config files: " << opt_videoname_left <<
".ppm" 59 <<
" and " << opt_videoname_right <<
".ppm" << std::endl;
69 g_right.
open(I_right);
71 #if defined(VISP_HAVE_X11) 74 #elif defined(VISP_HAVE_GDI) 83 display_left.
init(I_left, 100, 100,
"Model-based tracker (Left)");
84 display_right.
init(I_right, 110 + (
int)I_left.
getWidth(), 100,
"Model-based tracker (Right)");
87 std::vector<int> trackerTypes(2);
88 trackerTypes[0] = opt_tracker1;
89 trackerTypes[1] = opt_tracker2;
93 #if !defined(VISP_HAVE_MODULE_KLT) 94 if (opt_tracker >= 2) {
95 std::cout <<
"klt and hybrid model-based tracker are not available " 96 "since visp_klt module is missing" 103 tracker.loadConfigFile(objectname_left +
".xml", objectname_right +
".xml");
107 tracker.loadModel(objectname_left +
".cao", objectname_right +
".cao");
110 tracker.setDisplayFeatures(
true);
115 std::ifstream file_cRightMcLeft(
"cRightMcLeft.txt");
116 cRightMcLeft.
load(file_cRightMcLeft);
118 std::map<std::string, vpHomogeneousMatrix> mapOfCameraTransformationMatrix;
120 mapOfCameraTransformationMatrix[
"Camera2"] = cRightMcLeft;
122 tracker.setCameraTransformationMatrix(mapOfCameraTransformationMatrix);
126 tracker.initClick(I_left, I_right, objectname_left +
".init", objectname_right +
".init",
true);
129 while (!g_left.
end() && !g_right.
end()) {
137 tracker.track(I_left, I_right);
142 tracker.getPose(cLeftMo, cRightMo);
147 tracker.getCameraParameters(cam_left, cam_right);
148 tracker.display(I_left, I_right, cLeftMo, cRightMo, cam_left, cam_right,
vpColor::red, 2);
164 std::cerr <<
"Catch a ViSP exception: " << e.
what() << std::endl;
169 std::cout <<
"Install OpenCV and rebuild ViSP to use this example." << std::endl;
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.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Real-time 6D object pose tracking using its CAD model.
static void flush(const vpImage< unsigned char > &I)
void load(std::ifstream &f)
void open(vpImage< vpRGBa > &I)
const char * what() const
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.
void acquire(vpImage< vpRGBa > &I)
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))
void setFileName(const std::string &filename)