ViSP  2.10.0
tutorial-blob-tracker-live-firewire.cpp
1 #include <visp/vp1394CMUGrabber.h>
3 #include <visp/vp1394TwoGrabber.h>
4 #include <visp/vpDisplayGDI.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_DC1394_2) || defined(VISP_HAVE_CMU1394) || (VISP_HAVE_OPENCV_VERSION >= 0x020100)) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
12  vpImage<unsigned char> I; // Create a gray level image container
13 
14 #if defined(VISP_HAVE_DC1394_2)
15  vp1394TwoGrabber g(false);
16  g.open(I);
17 #elif defined(VISP_HAVE_CMU1394)
19  g.open(I);
20 #elif defined(VISP_HAVE_OPENCV)
21  cv::VideoCapture g(0); // open the default camera
22  if(!g.isOpened()) { // check if we succeeded
23  std::cout << "Failed to open the camera" << std::endl;
24  return -1;
25  }
26  cv::Mat frame;
27  g >> frame; // get a new frame from camera
28  vpImageConvert::convert(frame, I);
29 #endif
30 
31 #if defined(VISP_HAVE_X11)
32  vpDisplayX d(I, 0, 0, "Camera view");
33 #elif defined(VISP_HAVE_GDI)
34  vpDisplayGDI d(I, 0, 0, "Camera view");
35 #elif defined(VISP_HAVE_OPENCV)
36  vpDisplayOpenCV d(I, 0, 0, "Camera view");
37 #endif
38 
40  vpDot2 blob;
43  blob.setGraphics(true);
44  blob.setGraphicsThickness(2);
46 
47  vpImagePoint germ;
48  bool init_done = false;
49 
50  while(1) {
51  try {
52 #if defined(VISP_HAVE_DC1394_2) || defined(VISP_HAVE_CMU1394)
53  g.acquire(I);
54 #elif defined(VISP_HAVE_OPENCV)
55  g >> frame;
56  vpImageConvert::convert(frame, I);
57 #endif
59 
60  if (! init_done) {
61  vpDisplay::displayText(I, vpImagePoint(10,10), "Click in the blob to initialize the tracker", vpColor::red);
62  if (vpDisplay::getClick(I, germ, false)) {
64  blob.initTracking(I, germ);
66  init_done = true;
67  }
68  }
69  else {
71  blob.track(I);
73  }
74 
76  }
77  catch(...) {
78  init_done = false;
79  }
80  }
81 #endif
82 }
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: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
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)
Definition: vpDisplay.cpp:210
The vpDisplayOpenCV allows to display image using the opencv library.
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Definition: vpDot2.cpp:266
Class for firewire ieee1394 video devices using libdc1394-2.x api.
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