Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
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 #ifdef ENABLE_VISP_NAMESPACE
21  using namespace VISP_NAMESPACE_NAME;
22 #endif
23 
24  vpImage<unsigned char> I; // Create a gray level image container
25 
26 #if defined(VISP_HAVE_DC1394)
27  vp1394TwoGrabber g(false);
28  g.open(I);
29 #elif defined(VISP_HAVE_CMU1394)
31  g.open(I);
32 #elif defined(HAVE_OPENCV_VIDEOIO)
33  cv::VideoCapture g(0); // open the default camera
34  if (!g.isOpened()) { // check if we succeeded
35  std::cout << "Failed to open the camera" << std::endl;
36  return EXIT_FAILURE;
37  }
38  cv::Mat frame;
39  g >> frame; // get a new frame from camera
40  vpImageConvert::convert(frame, I);
41 #endif
42 
43 #if defined(VISP_HAVE_X11)
44  vpDisplayX d(I, 0, 0, "Camera view");
45 #elif defined(VISP_HAVE_GDI)
46  vpDisplayGDI d(I, 0, 0, "Camera view");
47 #elif defined(HAVE_OPENCV_HIGHGUI)
48  vpDisplayOpenCV d(I, 0, 0, "Camera view");
49 #endif
50 
52  vpDot2 blob;
55  blob.setGraphics(true);
56  blob.setGraphicsThickness(2);
58 
59  vpImagePoint germ;
60  bool init_done = false;
61 
62  while (1) {
63  try {
64 #if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394)
65  g.acquire(I);
66 #elif defined(HAVE_OPENCV_VIDEOIO)
67  g >> frame;
68  vpImageConvert::convert(frame, I);
69 #endif
71 
72  if (!init_done) {
73  vpDisplay::displayText(I, vpImagePoint(10, 10), "Click in the blob to initialize the tracker", vpColor::red);
74  if (vpDisplay::getClick(I, germ, false)) {
76  blob.initTracking(I, germ);
78  init_done = true;
79  }
80  }
81  else {
83  blob.track(I);
85  }
86 
88  }
89  catch (...) {
90  init_done = false;
91  }
92 }
93 #endif
94 }
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:217
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:130
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:135
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:125
void track(const vpImage< unsigned char > &I, bool canMakeTheWindowGrow=true)
Definition: vpDot2.cpp:452
void setGraphics(bool activate)
Definition: vpDot2.h:318
void setGraphicsThickness(unsigned int thickness)
Definition: vpDot2.h:326
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Definition: vpDot2.cpp:269
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