ViSP  2.10.0
tutorial-blob-tracker-live-v4l2.cpp
1 #include <visp/vpV4l2Grabber.h>
3 #include <visp/vpDisplayGDI.h>
4 #include <visp/vpDisplayGTK.h>
5 #include <visp/vpDisplayOpenCV.h>
6 #include <visp/vpDisplayX.h>
7 #include <visp/vpDot2.h>
8 
9 int main()
10 {
11 #if ((defined(VISP_HAVE_V4L2) || (VISP_HAVE_OPENCV_VERSION >= 0x020100)) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK)))
12  vpImage<unsigned char> I; // Create a gray level image container
13 
14 #if defined(VISP_HAVE_V4L2)
15  vpV4l2Grabber g;
16  g.open(I);
17 #elif defined(VISP_HAVE_OPENCV)
18  cv::VideoCapture g(0); // open the default camera
19  if(!g.isOpened()) { // check if we succeeded
20  std::cout << "Failed to open the camera" << std::endl;
21  return -1;
22  }
23  cv::Mat frame;
24  g >> frame; // get a new frame from camera
25  vpImageConvert::convert(frame, I);
26 #endif
27 
28 #if defined(VISP_HAVE_X11)
29  vpDisplayX d(I, 0, 0, "Camera view");
30 #elif defined(VISP_HAVE_GDI)
31  vpDisplayGDI d(I, 0, 0, "Camera view");
32 #elif defined(VISP_HAVE_OPENCV)
33  vpDisplayOpenCV d(I, 0, 0, "Camera view");
34 #elif defined(VISP_HAVE_GTK)
35  vpDisplayGTK d(I, 0, 0, "Camera view");
36 #endif
37 
38  vpDot2 blob;
39  blob.setGraphics(true);
40  blob.setGraphicsThickness(2);
41 
42  vpImagePoint germ;
43  bool init_done = false;
44  std::cout << "Click!!!" << std::endl;
45  while(1) {
46  try {
47 #if defined(VISP_HAVE_V4L2)
48  g.acquire(I);
49 #elif defined(VISP_HAVE_OPENCV)
50  g >> frame;
51  vpImageConvert::convert(frame, I);
52 #endif
54 
55  if (! init_done) {
56  vpDisplay::displayText(I, vpImagePoint(10,10), "Click in the blob to initialize the tracker", vpColor::red);
57  if (vpDisplay::getClick(I, germ, false)) {
58  blob.initTracking(I, germ);
59  init_done = true;
60  }
61  }
62  else {
63  blob.track(I);
64  }
66  }
67  catch(...) {
68  init_done = false;
69  }
70  }
71 #endif
72 }
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:132
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Definition: vpDisplay.cpp:887
Define the X11 console to display images.
Definition: vpDisplayX.h:152
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:127
void track(const vpImage< unsigned char > &I)
Definition: vpDot2.cpp:465
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2232
static const vpColor red
Definition: vpColor.h:167
void setGraphicsThickness(unsigned int t)
Definition: vpDot2.h:318
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:210
The vpDisplayOpenCV allows to display image using the opencv library.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
Definition: vpDisplayGTK.h:145
Class for the Video4Linux2 video device.
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Definition: vpDot2.cpp:266
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
void setGraphics(const bool activate)
Definition: vpDot2.h:312