Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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/gui/vpDisplayGDI.h>
8 #include <visp3/gui/vpDisplayOpenCV.h>
9 #include <visp3/gui/vpDisplayX.h>
10 #include <visp3/blob/vpDot2.h>
11 
12 int main()
13 {
14 #if (defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || (VISP_HAVE_OPENCV_VERSION >= 0x020100)) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
15  vpImage<unsigned char> I; // Create a gray level image container
16 
17 #if defined(VISP_HAVE_DC1394)
18  vp1394TwoGrabber g(false);
19  g.open(I);
20 #elif defined(VISP_HAVE_CMU1394)
22  g.open(I);
23 #elif defined(VISP_HAVE_OPENCV)
24  cv::VideoCapture g(0); // open the default camera
25  if(!g.isOpened()) { // check if we succeeded
26  std::cout << "Failed to open the camera" << std::endl;
27  return -1;
28  }
29  cv::Mat frame;
30  g >> frame; // get a new frame from camera
31  vpImageConvert::convert(frame, I);
32 #endif
33 
34 #if defined(VISP_HAVE_X11)
35  vpDisplayX d(I, 0, 0, "Camera view");
36 #elif defined(VISP_HAVE_GDI)
37  vpDisplayGDI d(I, 0, 0, "Camera view");
38 #elif defined(VISP_HAVE_OPENCV)
39  vpDisplayOpenCV d(I, 0, 0, "Camera view");
40 #endif
41 
43  vpDot2 blob;
46  blob.setGraphics(true);
47  blob.setGraphicsThickness(2);
49 
50  vpImagePoint germ;
51  bool init_done = false;
52 
53  while(1) {
54  try {
55 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394)
56  g.acquire(I);
57 #elif defined(VISP_HAVE_OPENCV)
58  g >> frame;
59  vpImageConvert::convert(frame, I);
60 #endif
62 
63  if (! init_done) {
64  vpDisplay::displayText(I, vpImagePoint(10,10), "Click in the blob to initialize the tracker", vpColor::red);
65  if (vpDisplay::getClick(I, germ, false)) {
67  blob.initTracking(I, germ);
69  init_done = true;
70  }
71  }
72  else {
74  blob.track(I);
76  }
77 
79  }
80  catch(...) {
81  init_done = false;
82  }
83  }
84 #endif
85 }
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
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:153
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:125
void track(const vpImage< unsigned char > &I)
Definition: vpDot2.cpp:461
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:163
void setGraphicsThickness(unsigned int t)
Definition: vpDot2.h:322
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 initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Definition: vpDot2.cpp:262
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:88
void setGraphics(const bool activate)
Definition: vpDot2.h:316