Visual Servoing Platform  version 3.3.0
tutorial-blob-tracker-live-v4l2.cpp
1 #include <visp3/core/vpConfig.h>
3 #ifdef VISP_HAVE_MODULE_SENSOR
4 #include <visp3/sensor/vpV4l2Grabber.h>
5 #endif
6 #include <visp3/blob/vpDot2.h>
7 #include <visp3/gui/vpDisplayGDI.h>
8 #include <visp3/gui/vpDisplayGTK.h>
9 #include <visp3/gui/vpDisplayOpenCV.h>
10 #include <visp3/gui/vpDisplayX.h>
11 
12 int main()
13 {
14 #if ((defined(VISP_HAVE_V4L2) || (VISP_HAVE_OPENCV_VERSION >= 0x020100)) && \
15  (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK)))
16  vpImage<unsigned char> I; // Create a gray level image container
17 
18 #if defined(VISP_HAVE_V4L2)
19  vpV4l2Grabber g;
20  g.open(I);
21 #elif defined(VISP_HAVE_OPENCV)
22  cv::VideoCapture g(0); // open the default camera
23  if (!g.isOpened()) { // check if we succeeded
24  std::cout << "Failed to open the camera" << std::endl;
25  return -1;
26  }
27  cv::Mat frame;
28  g >> frame; // get a new frame from camera
29  vpImageConvert::convert(frame, I);
30 #endif
31 
32 #if defined(VISP_HAVE_X11)
33  vpDisplayX d(I, 0, 0, "Camera view");
34 #elif defined(VISP_HAVE_GDI)
35  vpDisplayGDI d(I, 0, 0, "Camera view");
36 #elif defined(VISP_HAVE_OPENCV)
37  vpDisplayOpenCV d(I, 0, 0, "Camera view");
38 #elif defined(VISP_HAVE_GTK)
39  vpDisplayGTK d(I, 0, 0, "Camera view");
40 #endif
41 
42  vpDot2 blob;
43  blob.setGraphics(true);
44  blob.setGraphicsThickness(2);
45 
46  vpImagePoint germ;
47  bool init_done = false;
48  std::cout << "Click!!!" << std::endl;
49  while (1) {
50  try {
51 #if defined(VISP_HAVE_V4L2)
52  g.acquire(I);
53 #elif defined(VISP_HAVE_OPENCV)
54  g >> frame;
55  vpImageConvert::convert(frame, I);
56 #endif
58 
59  if (!init_done) {
60  vpDisplay::displayText(I, vpImagePoint(10, 10), "Click in the blob to initialize the tracker", vpColor::red);
61  if (vpDisplay::getClick(I, germ, false)) {
62  blob.initTracking(I, germ);
63  init_done = true;
64  }
65  } else {
66  blob.track(I);
67  }
69  } catch (...) {
70  init_done = false;
71  }
72  }
73 #endif
74 }
vpDisplayX
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:149
vpV4l2Grabber::open
void open(vpImage< unsigned char > &I)
Definition: vpV4l2Grabber.cpp:409
vpImageConvert::convert
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Definition: vpImageConvert.cpp:78
vpDot2::setGraphicsThickness
void setGraphicsThickness(unsigned int t)
Definition: vpDot2.h:300
vpDisplayGDI
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:127
vpDot2
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:125
vpV4l2Grabber::acquire
void acquire(vpImage< unsigned char > &I)
Definition: vpV4l2Grabber.cpp:525
vpDisplayOpenCV
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Definition: vpDisplayOpenCV.h:140
vpDisplay::display
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay_uchar.cpp:739
vpDisplayGTK
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:136
vpDisplay::displayText
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Definition: vpDisplay_uchar.cpp:663
vpDot2::initTracking
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Definition: vpDot2.cpp:250
vpImagePoint
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
vpV4l2Grabber
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
Definition: vpV4l2Grabber.h:133
vpDisplay::flush
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay_uchar.cpp:715
vpImage< unsigned char >
vpDot2::track
void track(const vpImage< unsigned char > &I, bool canMakeTheWindowGrow=true)
Definition: vpDot2.cpp:438
vpDisplay::getClick
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Definition: vpDisplay_uchar.cpp:764
vpColor::red
static const vpColor red
Definition: vpColor.h:178
vpDot2::setGraphics
void setGraphics(bool activate)
Definition: vpDot2.h:293