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