Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
tutorial-grabber-bebop2.cpp
1 
2 #include <visp3/core/vpImage.h>
3 #include <visp3/gui/vpDisplayGDI.h>
4 #include <visp3/gui/vpDisplayOpenCV.h>
5 #include <visp3/gui/vpDisplayX.h>
6 #include <visp3/robot/vpRobotBebop2.h>
7 
8 #include "record_helper.h"
9 
13 int main(int argc, char **argv)
14 {
15 #if defined(VISP_HAVE_ARSDK) && defined(VISP_HAVE_FFMPEG)
16  try {
17  std::string opt_seqname;
18  int opt_record_mode = 0;
19  int image_res = 0;
20  std::string ip_address = "192.168.42.1";
21 
22  for (int i = 1; i < argc; i++) {
23  if (std::string(argv[i]) == "--seqname")
24  opt_seqname = std::string(argv[i + 1]);
25  else if (std::string(argv[i]) == "--record")
26  opt_record_mode = std::atoi(argv[i + 1]);
27  else if (std::string(argv[i]) == "--ip" && i + 1 < argc) {
28  ip_address = std::string(argv[i + 1]);
29  i++;
30  } else if (std::string(argv[i]) == "--hd_resolution")
31  image_res = 1;
32  else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
33  std::cout << "\nUsage:\n"
34  << " " << argv[0] << " [--seqname <sequence name>] [--record <0: continuous | 1: single shot>]"
35  << " [--ip <drone ip>] [--hd_resolution]"
36  << " [--help] [-h]\n"
37  << std::endl
38  << "Description:\n"
39  << " --seqname <sequence name>\n"
40  << " Desired name for picture sequence (default: empty).\n\n"
41  << " --record <0: continuous | 1: single shot>\n"
42  << " Record mode (default : 0, continuous).\n\n"
43  << " --ip <drone ip>\n"
44  << " IP address of the drone to which you want to connect (default : 192.168.42.1).\n\n"
45  << " --hd_resolution\n"
46  << " Enables HD 720p images instead of default 480p.\n"
47  << " Caution : camera calibration settings are different for the two resolutions.\n\n"
48  << "--help, -h\n"
49  << " Print help message.\n\n"
50 
51  << "\nExample to visualize images:\n"
52  << " " << argv[0] << "\n"
53  << "\nExamples to record a sequence of 720p images from drone with ip different from default:\n"
54  << " " << argv[0] << " --seqname I%04d.png --ip 192.168.42.3 --hd_resolution\n"
55  << " " << argv[0] << " --seqname folder/I%04d.png --record 0 --ip 192.168.42.3 --hd_resolution\n"
56  << "\nExamples to record single shot images:\n"
57  << " " << argv[0] << " --seqname I%04d.png --record 1\n"
58  << " " << argv[0] << " --seqname folder/I%04d.png --record 1\n"
59  << std::endl;
60  return 0;
61  } else {
62  std::cout << "Error : unknown parameter " << argv[i] << std::endl
63  << "See " << argv[0] << " --help" << std::endl;
64  return 0;
65  }
66  }
67 
68  std::cout << "Recording : " << (opt_seqname.empty() ? "disabled" : "enabled") << std::endl;
69 
70  std::string text_record_mode =
71  std::string("Record mode: ") + (opt_record_mode ? std::string("single") : std::string("continuous"));
72 
73  if (!opt_seqname.empty()) {
74  std::cout << text_record_mode << std::endl;
75  std::cout << "Record name: " << opt_seqname << std::endl;
76  }
77  std::cout << "Image resolution : " << (image_res == 0 ? "480p." : "720p.") << std::endl << std::endl;
78 
79  vpImage<unsigned char> I(1, 1, 0);
80 
81  vpRobotBebop2 drone(false, true, ip_address);
82 
83  if (drone.isRunning()) {
84 
85  drone.setVideoResolution(image_res);
86 
87  drone.startStreaming();
88  drone.setExposure(1.5f);
89  drone.getGrayscaleImage(I);
90  } else {
91  std::cout << "Error : failed to setup drone control" << std::endl;
92  return 1;
93  }
94 
95  std::cout << "Image size : " << I.getWidth() << " " << I.getHeight() << std::endl;
96 
97 #ifdef VISP_HAVE_X11
98  vpDisplayX d(I);
99 #elif defined(VISP_HAVE_GDI)
100  vpDisplayGDI d(I);
101 #elif defined(VISP_HAVE_OPENCV)
102  vpDisplayOpenCV d(I);
103 #else
104  std::cout << "No image viewer is available..." << std::endl;
105 #endif
106 
107  bool quit = false;
108  while (!quit) {
109  double t = vpTime::measureTimeMs();
110  drone.getGrayscaleImage(I);
111 
113 
114  quit = record_helper(opt_seqname, opt_record_mode, I);
115 
116  std::stringstream ss;
117  ss << "Acquisition time: " << std::setprecision(3) << vpTime::measureTimeMs() - t << " ms";
118  vpDisplay::displayText(I, static_cast<int>(I.getHeight()) - 20, 10, ss.str(), vpColor::red);
119  vpDisplay::flush(I);
120  }
121  } catch (const vpException &e) {
122  std::cout << "Caught an exception: " << e << std::endl;
123  }
124 #else
125  (void)argc;
126  (void)argv;
127  std::cout << "Install Parrot ARSDK3 and ffmpeg, configure and build ViSP again to use this example" << std::endl;
128 #endif // #if defined(VISP_HAVE_ARSDK) && defined(VISP_HAVE_FFMPEG)
129 }
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
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:150
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:126
static const vpColor red
Definition: vpColor.h:179
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:186
unsigned int getWidth() const
Definition: vpImage.h:244