Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-mb-edge-tracker.cpp
1
2#include <visp3/core/vpConfig.h>
3#include <visp3/core/vpIoTools.h>
4#include <visp3/gui/vpDisplayFactory.h>
5#include <visp3/io/vpImageIo.h>
7#include <visp3/mbt/vpMbEdgeTracker.h>
9#include <visp3/io/vpVideoReader.h>
10
11int main(int argc, char **argv)
12{
13#if defined(VISP_HAVE_OPENCV) && defined(VISP_HAVE_DISPLAY)
14#ifdef ENABLE_VISP_NAMESPACE
15 using namespace VISP_NAMESPACE_NAME;
16#endif
17
18#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
19 std::shared_ptr<vpDisplay> display = vpDisplayFactory::createDisplay();
20#else
22#endif
23 try {
24 std::string videoname = "teabox.mp4";
25
26 for (int i = 1; i < argc; i++) {
27 if (std::string(argv[i]) == "--name" && i + 1 < argc) {
28 videoname = std::string(argv[++i]);
29 }
30 else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
31 std::cout << "\nUsage: " << argv[0]
32 << " [--name <video name>]"
33 << " [--help,-h]\n" << std::endl;
34#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
35 if (display != nullptr) {
36 delete display;
37 }
38#endif
39 return EXIT_SUCCESS;
40 }
41 }
42 std::string parentname = vpIoTools::getParent(videoname);
43 std::string objectname = vpIoTools::getNameWE(videoname);
44
45 if (!parentname.empty())
46 objectname = parentname + "/" + objectname;
47
48 std::cout << "Video name: " << videoname << std::endl;
49 std::cout << "Tracker requested config files: " << objectname << ".[init,"
50 << "xml,"
51 << "cao or wrl]" << std::endl;
52 std::cout << "Tracker optional config files: " << objectname << ".[ppm]" << std::endl;
53
61
63 g.setFileName(videoname);
64 g.open(I);
65
66 display->init(I, 100, 100, "Model-based edge tracker");
67
71 bool usexml = false;
73#if defined(VISP_HAVE_PUGIXML)
74 if (vpIoTools::checkFilename(objectname + ".xml")) {
75 tracker.loadConfigFile(objectname + ".xml");
76 usexml = true;
77 }
78#endif
80 if (!usexml) {
82 vpMe me;
83 me.setMaskSize(5);
84 me.setMaskNumber(180);
85 me.setRange(8);
87 me.setThreshold(20);
88 me.setMu1(0.5);
89 me.setMu2(0.5);
90 me.setSampleStep(4);
91 tracker.setMovingEdge(me);
92 cam.initPersProjWithoutDistortion(839, 839, 325, 243);
93 tracker.setCameraParameters(cam);
95 tracker.setAngleAppear(vpMath::rad(70));
96 tracker.setAngleDisappear(vpMath::rad(80));
99 tracker.setNearClippingDistance(0.1);
100 tracker.setFarClippingDistance(100.0);
103 tracker.setClipping(tracker.getClipping() | vpMbtPolygon::FOV_CLIPPING);
106 }
108 tracker.setOgreVisibilityTest(false);
109 tracker.setOgreShowConfigDialog(false);
112 if (vpIoTools::checkFilename(objectname + ".cao"))
113 tracker.loadModel(objectname + ".cao");
116 else if (vpIoTools::checkFilename(objectname + ".wrl"))
117 tracker.loadModel(objectname + ".wrl");
120 tracker.setDisplayFeatures(true);
123 tracker.initClick(I, objectname + ".init", true);
125
126 while (!g.end()) {
127 g.acquire(I);
130 tracker.track(I);
133 tracker.getPose(cMo);
136 tracker.getCameraParameters(cam);
137 tracker.display(I, cMo, cam, vpColor::red, 2);
139 vpDisplay::displayFrame(I, cMo, cam, 0.025, vpColor::none, 3);
140 vpDisplay::displayText(I, 10, 10, "A click to exit...", vpColor::red);
142 if (vpDisplay::getClick(I, false))
143 break;
144 }
146 }
147 catch (const vpException &e) {
148 std::cout << "Catch a ViSP exception: " << e << std::endl;
149 }
150#ifdef VISP_HAVE_OGRE
151 catch (Ogre::Exception &e) {
152 std::cout << "Catch an Ogre exception: " << e.getDescription() << std::endl;
153 }
154#endif
155#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
156 if (display != nullptr) {
157 delete display;
158 }
159#endif
160#else
161 (void)argc;
162 (void)argv;
163 std::cout << "Install OpenCV and rebuild ViSP to use this example." << std::endl;
164#endif
165}
Generic class defining intrinsic camera parameters.
static const vpColor red
Definition vpColor.h:198
static const vpColor none
Definition vpColor.h:210
Class that defines generic functionalities for display.
Definition vpDisplay.h:171
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:60
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
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:129
Make the complete tracking of an object by using its CAD model.
Definition vpMe.h:143
void setMu1(const double &mu_1)
Definition vpMe.h:408
void setRange(const unsigned int &range)
Definition vpMe.h:438
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
Definition vpMe.h:531
void setMaskNumber(const unsigned int &mask_number)
Definition vpMe.cpp:555
void setThreshold(const double &threshold)
Definition vpMe.h:489
void setSampleStep(const double &sample_step)
Definition vpMe.h:445
void setMaskSize(const unsigned int &mask_size)
Definition vpMe.cpp:563
void setMu2(const double &mu_2)
Definition vpMe.h:415
@ NORMALIZED_THRESHOLD
Definition vpMe.h:154
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void open(vpImage< vpRGBa > &I) VP_OVERRIDE
void setFileName(const std::string &filename)
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.