Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-me-line-tracker.cpp
1
2#include <visp3/core/vpConfig.h>
3#ifdef VISP_HAVE_MODULE_SENSOR
5#include <visp3/sensor/vp1394CMUGrabber.h>
6#include <visp3/sensor/vp1394TwoGrabber.h>
7#include <visp3/sensor/vpV4l2Grabber.h>
9#endif
11#include <visp3/gui/vpDisplayGDI.h>
12#include <visp3/gui/vpDisplayOpenCV.h>
13#include <visp3/gui/vpDisplayX.h>
16#include <visp3/me/vpMeLine.h>
18
19#if defined(HAVE_OPENCV_VIDEOIO)
20#include <opencv2/videoio.hpp>
21#endif
22
23int main()
24{
25#if (defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO))
26 try {
30
32#if defined(VISP_HAVE_DC1394)
33 vp1394TwoGrabber g(false);
34#elif defined(VISP_HAVE_CMU1394)
36#elif defined(VISP_HAVE_V4L2)
38#elif defined(HAVE_OPENCV_VIDEOIO)
39 cv::VideoCapture g(0); // open the default camera
40 if (!g.isOpened()) { // check if we succeeded
41 std::cout << "Failed to open the camera" << std::endl;
42 return EXIT_FAILURE;
43 }
44 cv::Mat frame;
45#endif
48#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
49 g.acquire(I);
50#elif defined(HAVE_OPENCV_VIDEOIO)
51 g >> frame; // get a new frame from camera
53#endif
55
57#if defined(VISP_HAVE_X11)
58 vpDisplayX d(I, 0, 0, "Camera view");
59#elif defined(VISP_HAVE_GDI)
60 vpDisplayGDI d(I, 0, 0, "Camera view");
61#elif defined(HAVE_OPENCV_HIGHGUI)
62 vpDisplayOpenCV d(I, 0, 0, "Camera view");
63#else
64 std::cout << "No image viewer is available..." << std::endl;
65#endif
71
73 vpMe me;
74 me.setRange(25);
76 me.setThreshold(20);
77 me.setSampleStep(10);
79
81 vpMeLine line;
82 line.setMe(&me);
84 line.initTracking(I);
86
88 while (1) {
89#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
90 g.acquire(I);
91#elif defined(HAVE_OPENCV_VIDEOIO)
92 g >> frame;
94#endif
96 line.track(I);
97 line.display(I, vpColor::red);
99 }
101 }
102 catch (const vpException &e) {
103 std::cout << "Catch an exception: " << e << std::endl;
104 }
105#endif
106}
Firewire cameras video capture based on CMU 1394 Digital Camera SDK.
void acquire(vpImage< unsigned char > &I)
Class for firewire ieee1394 video devices using libdc1394-2.x api.
static const vpColor red
Definition vpColor.h:211
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 void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
Definition vpException.h:59
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Definition of the vpImage class member functions.
Definition vpImage.h:135
Class that tracks in an image a line moving edges.
Definition vpMeLine.h:148
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1)
Definition vpMeLine.cpp:181
void track(const vpImage< unsigned char > &I)
Definition vpMeLine.cpp:649
void initTracking(const vpImage< unsigned char > &I)
Definition vpMeLine.cpp:186
@ RANGE_RESULT
Definition vpMeSite.h:75
void setDisplay(vpMeSite::vpMeSiteDisplayType select)
void setMe(vpMe *p_me)
Definition vpMe.h:122
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
@ NORMALIZED_THRESHOLD
Easy-to-use normalized likelihood threshold corresponding to the minimal luminance contrast to consid...
Definition vpMe.h:132
void setThreshold(const double &t)
Definition vpMe.h:435
Class that is a wrapper over the Video4Linux2 (V4L2) driver.