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