Visual Servoing Platform  version 3.1.0
tutorial-me-line-tracker.cpp
1 
2 #include <visp3/core/vpConfig.h>
3 #ifdef VISP_HAVE_MODULE_SENSOR
4 #include <visp3/sensor/vp1394CMUGrabber.h>
5 #include <visp3/sensor/vp1394TwoGrabber.h>
6 #include <visp3/sensor/vpV4l2Grabber.h>
7 #endif
8 #include <visp3/gui/vpDisplayGDI.h>
9 #include <visp3/gui/vpDisplayOpenCV.h>
10 #include <visp3/gui/vpDisplayX.h>
11 #include <visp3/me/vpMeLine.h>
12 
13 int main()
14 {
15 #if (defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_V4L2))
16  try {
18 
19 #if defined(VISP_HAVE_DC1394)
20  vp1394TwoGrabber g(false);
21 #elif defined(VISP_HAVE_CMU1394)
23 #elif defined(VISP_HAVE_V4L2)
24  vpV4l2Grabber g;
25 #elif defined(VISP_HAVE_OPENCV)
26  cv::VideoCapture g(0); // open the default camera
27  if (!g.isOpened()) { // check if we succeeded
28  std::cout << "Failed to open the camera" << std::endl;
29  return -1;
30  }
31  cv::Mat frame;
32  g >> frame; // get a new frame from camera
33  vpImageConvert::convert(frame, I);
34 #endif
35  g.open(I);
36  g.acquire(I);
37 
38 #if defined(VISP_HAVE_X11)
39  vpDisplayX d(I, 0, 0, "Camera view");
40 #elif defined(VISP_HAVE_GDI)
41  vpDisplayGDI d(I, 0, 0, "Camera view");
42 #elif defined(VISP_HAVE_OPENCV)
43  vpDisplayOpenCV d(I, 0, 0, "Camera view");
44 #else
45  std::cout << "No image viewer is available..." << std::endl;
46 #endif
47 
50 
51  vpMe me;
52  me.setRange(25);
53  me.setThreshold(15000);
54  me.setSampleStep(10);
55 
56  vpMeLine line;
57  line.setMe(&me);
59  line.initTracking(I);
60 
61  while (1) {
62 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
63  g.acquire(I);
64 #elif defined(VISP_HAVE_OPENCV)
65  g >> frame;
66  vpImageConvert::convert(frame, I);
67 #endif
69  line.track(I);
70  line.display(I, vpColor::red);
72  }
73  } catch (vpException &e) {
74  std::cout << "Catch an exception: " << e << std::endl;
75  }
76 #endif
77 }
void acquire(vpImage< unsigned char > &I)
void open(vpImage< unsigned char > &I)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
void setSampleStep(const double &s)
Definition: vpMe.h:278
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:151
error that can be emited by ViSP classes.
Definition: vpException.h:71
void track(const vpImage< unsigned char > &Im)
Definition: vpMeLine.cpp:745
Definition: vpMe.h:60
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:180
void display(const vpImage< unsigned char > &I, vpColor col)
Definition: vpMeLine.cpp:222
Firewire cameras video capture based on CMU 1394 Digital Camera SDK.
void setDisplay(vpMeSite::vpMeSiteDisplayType select)
Definition: vpMeTracker.h:102
static void display(const vpImage< unsigned char > &I)
Class that tracks in an image a line moving edges.
Definition: vpMeLine.h:151
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void initTracking(const vpImage< unsigned char > &I)
Definition: vpMeLine.cpp:234
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
void setThreshold(const double &t)
Definition: vpMe.h:300
Class for firewire ieee1394 video devices using libdc1394-2.x api.
void setRange(const unsigned int &r)
Definition: vpMe.h:271
void setMe(vpMe *p_me)
Definition: vpMeTracker.h:133