ViSP  2.10.0
tutorial-mb-edge-tracker.cpp
1 #include <visp/vpDisplayGDI.h>
3 #include <visp/vpDisplayOpenCV.h>
4 #include <visp/vpDisplayX.h>
5 #include <visp/vpImageIo.h>
6 #include <visp/vpIoTools.h>
8 #include <visp/vpMbEdgeTracker.h>
10 #include <visp/vpVideoReader.h>
11 
12 int main(int argc, char** argv)
13 {
14 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100) || defined(VISP_HAVE_FFMPEG)
15  try {
16  std::string videoname = "teabox.mpg";
17 
18  for (int i=0; i<argc; i++) {
19  if (std::string(argv[i]) == "--name")
20  videoname = std::string(argv[i+1]);
21  else if (std::string(argv[i]) == "--help") {
22  std::cout << "\nUsage: " << argv[0] << " [--name <video name>] [--help]\n" << std::endl;
23  return 0;
24  }
25  }
26  std::string parentname = vpIoTools::getParent(videoname);
27  std::string objectname = vpIoTools::getNameWE(videoname);
28 
29  if(! parentname.empty())
30  objectname = parentname + "/" + objectname;
31 
32  std::cout << "Video name: " << videoname << std::endl;
33  std::cout << "Tracker requested config files: " << objectname
34  << ".[init,"
35 #ifdef VISP_HAVE_XML2
36  << "xml,"
37 #endif
38  << "cao or wrl]" << std::endl;
39  std::cout << "Tracker optional config files: " << objectname << ".[ppm]" << std::endl;
40 
48 
49  vpVideoReader g;
50  g.setFileName(videoname);
51  g.open(I);
52 
53 #if defined(VISP_HAVE_X11)
54  vpDisplayX display;
55 #elif defined(VISP_HAVE_GDI)
56  vpDisplayGDI display;
57 #elif defined(VISP_HAVE_OPENCV)
58  vpDisplayOpenCV display;
59 #else
60  std::cout << "No image viewer is available..." << std::endl;
61  return 0;
62 #endif
63 
64  display.init(I, 100, 100,"Model-based edge tracker");
65 
67  vpMbEdgeTracker tracker;
69  bool usexml = false;
71 #ifdef VISP_HAVE_XML2
72  if(vpIoTools::checkFilename(objectname + ".xml")) {
73  tracker.loadConfigFile(objectname + ".xml");
74  usexml = true;
75  }
76 #endif
77  if (! usexml) {
80  vpMe me;
81  me.setMaskSize(5);
82  me.setMaskNumber(180);
83  me.setRange(8);
84  me.setThreshold(10000);
85  me.setMu1(0.5);
86  me.setMu2(0.5);
87  me.setSampleStep(4);
88  me.setNbTotalSample(250);
89  tracker.setMovingEdge(me);
90  cam.initPersProjWithoutDistortion(839, 839, 325, 243);
91  tracker.setCameraParameters(cam);
93  tracker.setAngleAppear( vpMath::rad(70) );
94  tracker.setAngleDisappear( vpMath::rad(80) );
97  tracker.setNearClippingDistance(0.1);
98  tracker.setFarClippingDistance(100.0);
104  }
106  tracker.setOgreVisibilityTest(false);
109  if(vpIoTools::checkFilename(objectname + ".cao"))
110  tracker.loadModel(objectname + ".cao");
113  else if(vpIoTools::checkFilename(objectname + ".wrl"))
114  tracker.loadModel(objectname + ".wrl");
117  tracker.setDisplayFeatures(true);
120  tracker.initClick(I, objectname + ".init", true);
122 
123  while(! g.end()){
124  g.acquire(I);
127  tracker.track(I);
130  tracker.getPose(cMo);
133  tracker.getCameraParameters(cam);
134  tracker.display(I, cMo, cam, vpColor::red, 2);
136  vpDisplay::displayFrame(I, cMo, cam, 0.025, vpColor::none, 3);
137  vpDisplay::displayText(I, 10, 10, "A click to exit...", vpColor::red);
138  vpDisplay::flush(I);
139  if (vpDisplay::getClick(I, false))
140  break;
141  }
144 #ifdef VISP_HAVE_XML2
146 #endif
147 #if defined(VISP_HAVE_COIN) && (COIN_MAJOR_VERSION == 3)
148  SoDB::finish();
149 #endif
150  }
152  catch(vpException e) {
153  std::cout << "Catch an exception: " << e << std::endl;
154  }
155 #else
156  (void)argc;
157  (void)argv;
158  std::cout << "Install OpenCV or ffmpeg and rebuild ViSP to use this example." << std::endl;
159 #endif
160 }
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void setMovingEdge(const vpMe &me)
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:220
virtual void setAngleDisappear(const double &a)
Definition: vpMbTracker.h:400
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void track(const vpImage< unsigned char > &I)
void setMaskNumber(const unsigned int &a)
Definition: vpMe.cpp:480
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:132
void setSampleStep(const double &s)
Definition: vpMe.h:271
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Definition: vpDisplay.cpp:887
void setNbTotalSample(const int &nb)
Definition: vpMe.h:199
Define the X11 console to display images.
Definition: vpDisplayX.h:152
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
static const vpColor none
Definition: vpColor.h:179
error that can be emited by ViSP classes.
Definition: vpException.h:76
Contains predetermined masks for sites and holds moving edges tracking parameters.
Definition: vpMe.h:70
Make the complete tracking of an object by using its CAD model.
virtual void setCameraParameters(const vpCameraParameters &camera)
static std::string getParent(const std::string &pathname)
Definition: vpIoTools.cpp:1220
void loadConfigFile(const std::string &configFile)
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2232
void setMu1(const double &mu_1)
Definition: vpMe.h:171
static const vpColor red
Definition: vpColor.h:167
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
virtual void setNearClippingDistance(const double &dist)
virtual void setOgreVisibilityTest(const bool &v)
static bool checkFilename(const char *filename)
Definition: vpIoTools.cpp:465
void open(vpImage< vpRGBa > &I)
void setMaskSize(const unsigned int &a)
Definition: vpMe.cpp:488
void getPose(vpHomogeneousMatrix &cMo_) const
Definition: vpMbTracker.h:328
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:210
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void getCameraParameters(vpCameraParameters &camera) const
Definition: vpMbTracker.h:213
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)
Definition: vpDisplay.cpp:375
virtual void setFarClippingDistance(const double &dist)
void setFileName(const char *filename)
virtual void setAngleAppear(const double &a)
Definition: vpMbTracker.h:389
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, const bool displayHelp=false)
static double rad(double deg)
Definition: vpMath.h:100
static void cleanup()
Definition: vpXmlParser.h:220
void setMu2(const double &mu_2)
Definition: vpMe.h:185
virtual void loadModel(const char *modelFile, const bool verbose=false)
static std::string getNameWE(const std::string &pathname)
Definition: vpIoTools.cpp:1207
void setThreshold(const double &t)
Definition: vpMe.h:299
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
virtual bool getClick(bool blocking=true)=0
void setDisplayFeatures(const bool displayF)
Definition: vpMbTracker.h:431
void setRange(const unsigned int &r)
Definition: vpMe.h:229
virtual void setClipping(const unsigned int &flags)