Visual Servoing Platform  version 3.0.0
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) || (VISP_HAVE_OPENCV_VERSION >= 0x020100))
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 #endif
33 
34 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
35  g.acquire(I);
36 #elif defined(VISP_HAVE_OPENCV)
37  g >> frame; // get a new frame from camera
38  vpImageConvert::convert(frame, I);
39 #endif
40 
41 #if defined(VISP_HAVE_X11)
42  vpDisplayX d(I, 0, 0, "Camera view");
43 #elif defined(VISP_HAVE_GDI)
44  vpDisplayGDI d(I, 0, 0, "Camera view");
45 #elif defined(VISP_HAVE_OPENCV)
46  vpDisplayOpenCV d(I, 0, 0, "Camera view");
47 #else
48  std::cout << "No image viewer is available..." << std::endl;
49 #endif
50 
53 
54  vpMe me;
55  me.setRange(25);
56  me.setThreshold(15000);
57  me.setSampleStep(10);
58 
59  vpMeEllipse ellipse;
60  ellipse.setMe(&me);
62  ellipse.initTracking(I);
63 
64  while(1) {
65 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394)
66  g.acquire(I);
67 #elif defined(VISP_HAVE_OPENCV)
68  g >> frame;
69  vpImageConvert::convert(frame, I);
70 #endif
72  ellipse.track(I);
73  ellipse.display(I, vpColor::red);
75  }
76  }
77  catch(vpException e) {
78  std::cout << "Catch an exception: " << e << std::endl;
79  }
80 #endif
81 }
void acquire(vpImage< unsigned char > &I)
void initTracking(const 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:128
void setSampleStep(const double &s)
Definition: vpMe.h:260
Define the X11 console to display images.
Definition: vpDisplayX.h:148
error that can be emited by ViSP classes.
Definition: vpException.h:73
Class that tracks an ellipse moving edges.
Definition: vpMeEllipse.h:95
Definition: vpMe.h:59
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2233
static const vpColor red
Definition: vpColor.h:163
void track(const vpImage< unsigned char > &Im)
Firewire cameras video capture based on CMU 1394 Digital Camera SDK.
void setDisplay(vpMeSite::vpMeSiteDisplayType select)
Definition: vpMeTracker.h:101
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:206
The vpDisplayOpenCV allows to display image using the opencv library.
void display(const vpImage< unsigned char > &I, vpColor col)
Class for the Video4Linux2 video device.
void setThreshold(const double &t)
Definition: vpMe.h:288
Class for firewire ieee1394 video devices using libdc1394-2.x api.
void setRange(const unsigned int &r)
Definition: vpMe.h:218
void setMe(vpMe *p_me)
Definition: vpMeTracker.h:135