Visual Servoing Platform  version 3.4.0
tutorial-blob-tracker-live-firewire.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 #endif
7 #include <visp3/blob/vpDot2.h>
8 #include <visp3/gui/vpDisplayGDI.h>
9 #include <visp3/gui/vpDisplayOpenCV.h>
10 #include <visp3/gui/vpDisplayX.h>
11 
12 int main()
13 {
14 #if (defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || (VISP_HAVE_OPENCV_VERSION >= 0x020100)) && \
15  (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
16  vpImage<unsigned char> I; // Create a gray level image container
17 
18 #if defined(VISP_HAVE_DC1394)
19  vp1394TwoGrabber g(false);
20  g.open(I);
21 #elif defined(VISP_HAVE_CMU1394)
23  g.open(I);
24 #elif defined(VISP_HAVE_OPENCV)
25  cv::VideoCapture g(0); // open the default camera
26  if (!g.isOpened()) { // check if we succeeded
27  std::cout << "Failed to open the camera" << std::endl;
28  return -1;
29  }
30  cv::Mat frame;
31  g >> frame; // get a new frame from camera
32  vpImageConvert::convert(frame, I);
33 #endif
34 
35 #if defined(VISP_HAVE_X11)
36  vpDisplayX d(I, 0, 0, "Camera view");
37 #elif defined(VISP_HAVE_GDI)
38  vpDisplayGDI d(I, 0, 0, "Camera view");
39 #elif defined(VISP_HAVE_OPENCV)
40  vpDisplayOpenCV d(I, 0, 0, "Camera view");
41 #endif
42 
44  vpDot2 blob;
47  blob.setGraphics(true);
48  blob.setGraphicsThickness(2);
50 
51  vpImagePoint germ;
52  bool init_done = false;
53 
54  while (1) {
55  try {
56 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394)
57  g.acquire(I);
58 #elif defined(VISP_HAVE_OPENCV)
59  g >> frame;
60  vpImageConvert::convert(frame, I);
61 #endif
63 
64  if (!init_done) {
65  vpDisplay::displayText(I, vpImagePoint(10, 10), "Click in the blob to initialize the tracker", vpColor::red);
66  if (vpDisplay::getClick(I, germ, false)) {
68  blob.initTracking(I, germ);
70  init_done = true;
71  }
72  } else {
74  blob.track(I);
76  }
77 
79  } catch (...) {
80  init_done = false;
81  }
82  }
83 #endif
84 }
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void open(vpImage< unsigned char > &I)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
void setGraphics(bool activate)
Definition: vpDot2.h:314
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:150
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:126
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:217
void setGraphicsThickness(unsigned int t)
Definition: vpDot2.h:321
Firewire cameras video capture based on CMU 1394 Digital Camera SDK.
void acquire(vpImage< unsigned char > &I)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void track(const vpImage< unsigned char > &I, bool canMakeTheWindowGrow=true)
Definition: vpDot2.cpp:441
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Definition: vpDot2.cpp:253
Class for firewire ieee1394 video devices using libdc1394-2.x api.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87