Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
tutorial-me-line-tracker.cpp
1 #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 
23 int main()
24 {
25 #if (defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO))
26 #ifdef ENABLE_VISP_NAMESPACE
27  using namespace VISP_NAMESPACE_NAME;
28 #endif
29  try {
33 
35 #if defined(VISP_HAVE_DC1394)
36  vp1394TwoGrabber g(false);
37 #elif defined(VISP_HAVE_CMU1394)
39 #elif defined(VISP_HAVE_V4L2)
40  vpV4l2Grabber g;
41 #elif defined(HAVE_OPENCV_VIDEOIO)
42  cv::VideoCapture g(0); // open the default camera
43  if (!g.isOpened()) { // check if we succeeded
44  std::cout << "Failed to open the camera" << std::endl;
45  return EXIT_FAILURE;
46  }
47  cv::Mat frame;
48 #endif
51 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
52  g.acquire(I);
53 #elif defined(HAVE_OPENCV_VIDEOIO)
54  g >> frame; // get a new frame from camera
55  vpImageConvert::convert(frame, I);
56 #endif
58 
60 #if defined(VISP_HAVE_X11)
61  vpDisplayX d(I, 0, 0, "Camera view");
62 #elif defined(VISP_HAVE_GDI)
63  vpDisplayGDI d(I, 0, 0, "Camera view");
64 #elif defined(HAVE_OPENCV_HIGHGUI)
65  vpDisplayOpenCV d(I, 0, 0, "Camera view");
66 #else
67  std::cout << "No image viewer is available..." << std::endl;
68 #endif
74 
76  vpMe me;
77  me.setRange(25);
79  me.setThreshold(20);
80  me.setSampleStep(10);
82 
84  vpMeLine line;
85  line.setMe(&me);
87  line.initTracking(I);
89 
91  while (1) {
92 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
93  g.acquire(I);
94 #elif defined(HAVE_OPENCV_VIDEOIO)
95  g >> frame;
96  vpImageConvert::convert(frame, I);
97 #endif
99  line.track(I);
100  line.display(I, vpColor::red);
101  vpDisplay::flush(I);
102  }
104  }
105  catch (const vpException &e) {
106  std::cout << "Catch an exception: " << e << std::endl;
107  }
108 #endif
109 }
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:217
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:130
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:135
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:60
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Class that tracks in an image a line moving edges.
Definition: vpMeLine.h:152
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1)
Definition: vpMeLine.cpp:194
void track(const vpImage< unsigned char > &I)
Definition: vpMeLine.cpp:664
void initTracking(const vpImage< unsigned char > &I)
Definition: vpMeLine.cpp:199
@ RANGE_RESULT
Definition: vpMeSite.h:78
void setDisplay(vpMeSite::vpMeSiteDisplayType select)
Definition: vpMeTracker.h:232
void setMe(vpMe *me)
Definition: vpMeTracker.h:260
Definition: vpMe.h:134
void setRange(const unsigned int &range)
Definition: vpMe.h:415
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
Definition: vpMe.h:505
void setThreshold(const double &threshold)
Definition: vpMe.h:466
void setSampleStep(const double &sample_step)
Definition: vpMe.h:422
@ NORMALIZED_THRESHOLD
Definition: vpMe.h:145
Class that is a wrapper over the Video4Linux2 (V4L2) driver.