Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-mb-edge-tracker.cpp
1
2#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/vpMbEdgeTracker.h>
10#include <visp3/io/vpVideoReader.h>
11
12int main(int argc, char **argv)
13{
14#if defined(VISP_HAVE_OPENCV)
15 try {
16 std::string videoname = "teabox.mp4";
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" || std::string(argv[i]) == "-h") {
22 std::cout << "\nUsage: " << argv[0] << " [--name <video name>] [--help] [-h]\n" << std::endl;
23 return EXIT_SUCCESS;
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 << ".[init,"
34 << "xml,"
35 << "cao or wrl]" << std::endl;
36 std::cout << "Tracker optional config files: " << objectname << ".[ppm]" << std::endl;
37
45
47 g.setFileName(videoname);
48 g.open(I);
49
50#if defined(VISP_HAVE_X11)
51 vpDisplayX display;
52#elif defined(VISP_HAVE_GDI)
53 vpDisplayGDI display;
54#elif defined(HAVE_OPENCV_HIGHGUI)
55 vpDisplayOpenCV display;
56#else
57 std::cout << "No image viewer is available..." << std::endl;
58 return EXIT_FAILURE;
59#endif
60
61 display.init(I, 100, 100, "Model-based edge tracker");
62
64 vpMbEdgeTracker tracker;
66 bool usexml = false;
68 if (vpIoTools::checkFilename(objectname + ".xml")) {
69 tracker.loadConfigFile(objectname + ".xml");
70 usexml = true;
71 }
73 if (!usexml) {
75 vpMe me;
76 me.setMaskSize(5);
77 me.setMaskNumber(180);
78 me.setRange(8);
80 me.setThreshold(20);
81 me.setMu1(0.5);
82 me.setMu2(0.5);
83 me.setSampleStep(4);
84 tracker.setMovingEdge(me);
85 cam.initPersProjWithoutDistortion(839, 839, 325, 243);
86 tracker.setCameraParameters(cam);
88 tracker.setAngleAppear(vpMath::rad(70));
89 tracker.setAngleDisappear(vpMath::rad(80));
92 tracker.setNearClippingDistance(0.1);
93 tracker.setFarClippingDistance(100.0);
99 }
101 tracker.setOgreVisibilityTest(false);
102 tracker.setOgreShowConfigDialog(false);
105 if (vpIoTools::checkFilename(objectname + ".cao"))
106 tracker.loadModel(objectname + ".cao");
109 else if (vpIoTools::checkFilename(objectname + ".wrl"))
110 tracker.loadModel(objectname + ".wrl");
113 tracker.setDisplayFeatures(true);
116 tracker.initClick(I, objectname + ".init", true);
118
119 while (!g.end()) {
120 g.acquire(I);
123 tracker.track(I);
126 tracker.getPose(cMo);
129 tracker.getCameraParameters(cam);
130 tracker.display(I, cMo, cam, vpColor::red, 2);
132 vpDisplay::displayFrame(I, cMo, cam, 0.025, vpColor::none, 3);
133 vpDisplay::displayText(I, 10, 10, "A click to exit...", vpColor::red);
135 if (vpDisplay::getClick(I, false))
136 break;
137 }
139 }
140 catch (const vpException &e) {
141 std::cout << "Catch a ViSP exception: " << e << std::endl;
142 }
143#ifdef VISP_HAVE_OGRE
144 catch (Ogre::Exception &e) {
145 std::cout << "Catch an Ogre exception: " << e.getDescription() << std::endl;
146 }
147#endif
148#else
149 (void)argc;
150 (void)argv;
151 std::cout << "Install OpenCV and rebuild ViSP to use this example." << std::endl;
152#endif
153}
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
static const vpColor red
Definition vpColor.h:211
static const vpColor none
Definition vpColor.h:223
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:132
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &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), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Definition vpException.h:59
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:135
static bool checkFilename(const std::string &filename)
static std::string getNameWE(const std::string &pathname)
static std::string getParent(const std::string &pathname)
static double rad(double deg)
Definition vpMath.h:116
Make the complete tracking of an object by using its CAD model.
virtual void setCameraParameters(const vpCameraParameters &cam)
virtual void setNearClippingDistance(const double &dist)
virtual void setFarClippingDistance(const double &dist)
virtual void track(const vpImage< unsigned char > &I)
virtual void loadConfigFile(const std::string &configFile, bool verbose=true)
virtual void setClipping(const unsigned int &flags)
virtual void setOgreVisibilityTest(const bool &v)
void setMovingEdge(const vpMe &me)
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
virtual void setOgreShowConfigDialog(bool showConfigDialog)
virtual void getCameraParameters(vpCameraParameters &cam) const
virtual void setDisplayFeatures(bool displayF)
virtual void getPose(vpHomogeneousMatrix &cMo) const
virtual void setAngleDisappear(const double &a)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setAngleAppear(const double &a)
virtual unsigned int getClipping() const
Definition vpMe.h:122
void setMu1(const double &mu_1)
Definition vpMe.h:353
void setSampleStep(const double &s)
Definition vpMe.h:390
void setRange(const unsigned int &r)
Definition vpMe.h:383
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
Definition vpMe.h:445
void setMaskSize(const unsigned int &a)
Definition vpMe.cpp:452
void setMu2(const double &mu_2)
Definition vpMe.h:360
@ NORMALIZED_THRESHOLD
Easy-to-use normalized likelihood threshold corresponding to the minimal luminance contrast to consid...
Definition vpMe.h:132
void setMaskNumber(const unsigned int &a)
Definition vpMe.cpp:445
void setThreshold(const double &t)
Definition vpMe.h:435
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void acquire(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)