Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
tutorial-me-ellipse-tracker.cpp
1 #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 #if defined(HAVE_OPENCV_VIDEOIO)
14 #include <opencv2/videoio.hpp>
15 #endif
16 
17 int main()
18 {
19 #if (defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO))
20 #ifdef ENABLE_VISP_NAMESPACE
21  using namespace VISP_NAMESPACE_NAME;
22 #endif
23  try {
25 
26 #if defined(VISP_HAVE_DC1394)
27  vp1394TwoGrabber g(false);
28 #elif defined(VISP_HAVE_CMU1394)
30 #elif defined(VISP_HAVE_V4L2)
31  vpV4l2Grabber g;
32 #elif defined(HAVE_OPENCV_VIDEOIO)
33  cv::VideoCapture g(0); // open the default camera
34  if (!g.isOpened()) { // check if we succeeded
35  std::cout << "Failed to open the camera" << std::endl;
36  return EXIT_FAILURE;
37  }
38  cv::Mat frame;
39 #endif
40 
41 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
42  g.acquire(I);
43 #elif defined(HAVE_OPENCV_VIDEOIO)
44  g >> frame; // get a new frame from camera
45  vpImageConvert::convert(frame, I);
46 #endif
47 
48 #if defined(VISP_HAVE_X11)
49  vpDisplayX d(I, 0, 0, "Camera view");
50 #elif defined(VISP_HAVE_GDI)
51  vpDisplayGDI d(I, 0, 0, "Camera view");
52 #elif defined(HAVE_OPENCV_HIGHGUI)
53  vpDisplayOpenCV d(I, 0, 0, "Camera view");
54 #else
55  std::cout << "No image viewer is available..." << std::endl;
56 #endif
57 
60 
61  vpMe me;
62  me.setRange(25);
64  me.setThreshold(20);
65  me.setSampleStep(10);
66 
68  vpMeEllipse ellipse;
69  ellipse.setMe(&me);
71  ellipse.initTracking(I);
73 
74  while (1) {
75 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
76  g.acquire(I);
77 #elif defined(HAVE_OPENCV_VIDEOIO)
78  g >> frame;
79  vpImageConvert::convert(frame, I);
80 #endif
82  ellipse.track(I);
83  ellipse.display(I, vpColor::red);
85  }
86  }
87  catch (const vpException &e) {
88  std::cout << "Catch an exception: " << e << std::endl;
89  }
90 #endif
91 }
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...
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 an ellipse using moving edges.
Definition: vpMeEllipse.h:96
void display(const vpImage< unsigned char > &I, const vpColor &col, unsigned int thickness=1)
void initTracking(const vpImage< unsigned char > &I, bool trackCircle=false, bool trackArc=false)
void track(const vpImage< unsigned char > &I)
@ 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.