Visual Servoing Platform  version 3.6.1 under development (2024-04-19)
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  try {
30 
32 #if defined(VISP_HAVE_DC1394)
33  vp1394TwoGrabber g(false);
34 #elif defined(VISP_HAVE_CMU1394)
36 #elif defined(VISP_HAVE_V4L2)
37  vpV4l2Grabber g;
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
52  vpImageConvert::convert(frame, I);
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;
93  vpImageConvert::convert(frame, I);
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).
Definition: vpDisplayGDI.h:128
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:128
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)
Class that tracks in an image a line moving edges.
Definition: vpMeLine.h:147
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1)
Definition: vpMeLine.cpp:192
void track(const vpImage< unsigned char > &I)
Definition: vpMeLine.cpp:662
void initTracking(const vpImage< unsigned char > &I)
Definition: vpMeLine.cpp:197
@ RANGE_RESULT
Definition: vpMeSite.h:75
void setDisplay(vpMeSite::vpMeSiteDisplayType select)
Definition: vpMeTracker.h:250
void setMe(vpMe *me)
Definition: vpMeTracker.h:278
Definition: vpMe.h:124
void setRange(const unsigned int &range)
Definition: vpMe.h:429
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
Definition: vpMe.h:519
void setThreshold(const double &threshold)
Definition: vpMe.h:480
void setSampleStep(const double &sample_step)
Definition: vpMe.h:436
@ NORMALIZED_THRESHOLD
Definition: vpMe.h:135
Class that is a wrapper over the Video4Linux2 (V4L2) driver.