Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
tutorial-grabber-1394.cpp
1 #include <visp3/core/vpImage.h>
3 #include <visp3/gui/vpDisplayX.h>
4 #include <visp3/gui/vpDisplayOpenCV.h>
5 #include <visp3/sensor/vp1394TwoGrabber.h>
6 
7 #include "record_helper.h"
8 
9 int main(int argc, char **argv)
10 {
11 #ifdef VISP_HAVE_DC1394
12  try {
13  std::string opt_seqname;
14  int opt_record_mode = 0;
15  bool opt_change_settings = false;
16 
17  for (int i = 0; i < argc; i++) {
18  if (std::string(argv[i]) == "--seqname")
19  opt_seqname = std::string(argv[i + 1]);
20  else if (std::string(argv[i]) == "--record")
21  opt_record_mode = std::atoi(argv[i + 1]);
22  else if (std::string(argv[i]) == "--change_settings")
23  opt_change_settings = true;
24  else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
25  std::cout << "\nUsage: " << argv[0]
26  << " [--seqname <sequence name (default: empty>] [--record <0: continuous | 1: single shot (default: 0)>]"
27  " [--change_settings] [--help] [-h]\n"
28  << "\nExample to visualize images:\n"
29  << " " << argv[0] << "\n"
30  << "\nExamples to record a sequence:\n"
31  << " " << argv[0] << " --seqname I%04d.png \n"
32  << " " << argv[0] << " --seqname folder/I%04d.png --record 0\n"
33  << "\nExamples to record single shot images:\n"
34  << " " << argv[0] << " --seqname I%04d.png --record 1\n"
35  << " " << argv[0] << " --seqname folder/I%04d.png --record 1\n"
36  << std::endl;
37  return 0;
38  }
39  }
40 
41  std::cout << "Settings : " << (opt_change_settings ? "modified" : "current") << std::endl;
42  std::cout << "Recording : " << (opt_seqname.empty() ? "disabled" : "enabled") << std::endl;
43 
44  std::string text_record_mode = std::string("Record mode: ") + (opt_record_mode ? std::string("single") : std::string("continuous"));
45 
46  if (! opt_seqname.empty()) {
47  std::cout << text_record_mode << std::endl;
48  std::cout << "Record name: " << opt_seqname << std::endl;
49  }
50 
51  vpImage<unsigned char> I; // Create a gray level image container
52  bool reset = false; // Disable bus reset during construction (default)
54  vp1394TwoGrabber g(reset); // Create a grabber based on libdc1394-2.x third party lib
56 
58  if (opt_change_settings) {
59  try {
61  g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_60);
62  }
63  catch(...) { // If settings are not available just catch execption to
64  // continue with default settings
65  std::cout << "Warning: cannot modify camera settings" << std::endl;
66  }
67  }
70  g.open(I);
72 
73  std::cout << "Image size : " << I.getWidth() << " " << I.getHeight() << std::endl;
74 
75 #ifdef VISP_HAVE_X11
76  vpDisplayX d(I);
77 #elif defined(VISP_HAVE_OPENCV)
78  vpDisplayOpenCV d(I);
79 #else
80  std::cout << "No image viewer is available..." << std::endl;
81 #endif
82 
83  bool quit = false;
84  while (! quit) {
85  double t = vpTime::measureTimeMs();
87  g.acquire(I);
91  quit = record_helper(opt_seqname, opt_record_mode, I);
93  std::stringstream ss;
94  ss << "Acquisition time: " << std::setprecision(3) << vpTime::measureTimeMs() - t << " ms";
95  vpDisplay::displayText(I, I.getHeight() - 20, 10, ss.str(), vpColor::red);
97  }
98  } catch (const vpException &e) {
99  std::cout << "Catch an exception: " << e << std::endl;
100  }
101 #else
102  (void) argc;
103  (void) argv;
104  std::cout << "Install libdc1394, configure and build ViSP again to use this example" << std::endl;
105 #endif
106 }
unsigned int getWidth() const
Definition: vpImage.h:239
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:151
error that can be emited by ViSP classes.
Definition: vpException.h:71
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
Definition: vpTime.cpp:88
static const vpColor red
Definition: vpColor.h:180
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
unsigned int getHeight() const
Definition: vpImage.h:178
Class for firewire ieee1394 video devices using libdc1394-2.x api.