Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
tutorial-grabber-1394-writer.cpp
1 
2 #include <visp3/core/vpConfig.h>
3 #include <visp3/core/vpImage.h>
4 #include <visp3/gui/vpDisplayFactory.h>
5 #include <visp3/io/vpVideoWriter.h>
6 #include <visp3/sensor/vp1394TwoGrabber.h>
7 
8 int main(int argc, char **)
9 {
10 #ifdef VISP_HAVE_DC1394
11 #ifdef ENABLE_VISP_NAMESPACE
12  using namespace VISP_NAMESPACE_NAME;
13 #endif
14 #ifdef VISP_HAVE_DISPLAY
16 #else
17  std::cout << "No image viewer is available..." << std::endl;
18 #endif
19  try {
20  bool save = false;
21  if (argc == 2) {
22  save = true;
23  }
24 
25  vpImage<vpRGBa> I; // Create a color image container
26  bool reset = true; // Enable bus reset during construction (default)
27  vp1394TwoGrabber g(reset); // Create a grabber based on libdc1394-2.x third party lib
28 
30  g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_60);
31  g.open(I);
32 
33  std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;
34 
35  vpVideoWriter writer;
36  writer.setFileName("./I%04d.pgm");
37  if (save)
38  writer.open(I);
39 
40 #ifdef VISP_HAVE_DISPLAY
41  d->init(I);
42  while (1)
43 #else
44  // for loop when no display is available to avoid infinite while loop
45  for (unsigned int i = 0; i < 1000; ++i)
46 #endif
47  {
48  g.acquire(I);
49 
50  if (save)
51  writer.saveFrame(I);
52 
53 #ifdef VISP_HAVE_DISPLAY
56 
57  if (vpDisplay::getClick(I, false)) {
58  break;
59  }
60 #endif
61  }
62 
63  if (save) {
64  writer.close();
65  }
66  }
67  catch (const vpException &e) {
68  std::cout << "Catch an exception: " << e << std::endl;
69  }
70 #ifdef VISP_HAVE_DISPLAY
71  if (d != nullptr) {
72  delete d;
73  }
74 #endif
75 #else
76  (void)argc;
77 #endif
78 
79  return EXIT_SUCCESS;
80 }
Class for firewire ieee1394 video devices using libdc1394-2.x api.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
Class that defines generic functionalities for display.
Definition: vpDisplay.h:178
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)
error that can be emitted by ViSP classes.
Definition: vpException.h:60
unsigned int getWidth() const
Definition: vpImage.h:242
unsigned int getHeight() const
Definition: vpImage.h:181
Class that enables to write easily a video file or a sequence of images.
void saveFrame(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
void open(vpImage< vpRGBa > &I)
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.