Visual Servoing Platform  version 3.5.1 under development (2023-06-06)
tutorial-me-ellipse-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/vpMeEllipse.h>
12 
13 int main()
14 {
15 #if (defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_V4L2) || \
16  (VISP_HAVE_OPENCV_VERSION >= 0x020100))
17  try {
19 
20 #if defined(VISP_HAVE_DC1394)
21  vp1394TwoGrabber g(false);
22 #elif defined(VISP_HAVE_CMU1394)
24 #elif defined(VISP_HAVE_V4L2)
25  vpV4l2Grabber g;
26 #elif defined(VISP_HAVE_OPENCV)
27  cv::VideoCapture g(0); // open the default camera
28  if (!g.isOpened()) { // check if we succeeded
29  std::cout << "Failed to open the camera" << std::endl;
30  return EXIT_FAILURE;
31  }
32  cv::Mat frame;
33 #endif
34 
35 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
36  g.acquire(I);
37 #elif defined(VISP_HAVE_OPENCV)
38  g >> frame; // get a new frame from camera
39  vpImageConvert::convert(frame, I);
40 #endif
41 
42 #if defined(VISP_HAVE_X11)
43  vpDisplayX d(I, 0, 0, "Camera view");
44 #elif defined(VISP_HAVE_GDI)
45  vpDisplayGDI d(I, 0, 0, "Camera view");
46 #elif defined(VISP_HAVE_OPENCV)
47  vpDisplayOpenCV d(I, 0, 0, "Camera view");
48 #else
49  std::cout << "No image viewer is available..." << std::endl;
50 #endif
51 
54 
55  vpMe me;
56  me.setRange(25);
57  me.setThreshold(15000);
58  me.setSampleStep(10);
59 
60  vpMeEllipse ellipse;
61  ellipse.setMe(&me);
63  ellipse.initTracking(I);
64 
65  while (1) {
66 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
67  g.acquire(I);
68 #elif defined(VISP_HAVE_OPENCV)
69  g >> frame;
70  vpImageConvert::convert(frame, I);
71 #endif
73  ellipse.track(I);
74  ellipse.display(I, vpColor::red);
76  }
77  } catch (const vpException &e) {
78  std::cout << "Catch an exception: " << e << std::endl;
79  }
80 #endif
81 }
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:129
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 emited by ViSP classes.
Definition: vpException.h:72
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Class that tracks an ellipse using moving edges.
Definition: vpMeEllipse.h:95
void initTracking(const vpImage< unsigned char > &I, bool trackArc=false)
void track(const vpImage< unsigned char > &I)
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1)
@ RANGE_RESULT
Definition: vpMeSite.h:69
void setDisplay(vpMeSite::vpMeSiteDisplayType select)
Definition: vpMeTracker.h:148
void setMe(vpMe *p_me)
Definition: vpMeTracker.h:169
Definition: vpMe.h:119
void setSampleStep(const double &s)
Definition: vpMe.h:337
void setRange(const unsigned int &r)
Definition: vpMe.h:330
void setThreshold(const double &t)
Definition: vpMe.h:364
Class that is a wrapper over the Video4Linux2 (V4L2) driver.