2#include <visp3/core/vpConfig.h>
3#include <visp3/core/vpImage.h>
4#include <visp3/core/vpXmlParserCamera.h>
5#include <visp3/gui/vpDisplayFactory.h>
6#include <visp3/io/vpImageStorageWorker.h>
7#include <visp3/sensor/vpRealSense2.h>
9void usage(
const char *argv[],
int error)
11 std::cout <<
"SYNOPSIS" << std::endl
12 <<
" " << argv[0] <<
" [--fps <6|15|30|60>]"
13 <<
" [--width <image width>]"
14 <<
" [--height <image height>]"
15 <<
" [--seqname <sequence name>]"
16 <<
" [--save-distortion]"
17 <<
" [--record <mode>]"
19 <<
" [--help] [-h]" << std::endl
21 std::cout <<
"DESCRIPTION" << std::endl
22 <<
" --fps <6|15|30|60>" << std::endl
23 <<
" Frames per second." << std::endl
24 <<
" Default: 30." << std::endl
26 <<
" --width <image width>" << std::endl
27 <<
" Default: 640." << std::endl
29 <<
" --height <image height>" << std::endl
30 <<
" Default: 480." << std::endl
32 <<
" --seqname <sequence name>" << std::endl
33 <<
" Name of the sequence of image to create (ie: /tmp/image%04d.jpg)." << std::endl
34 <<
" Default: empty." << std::endl
36 <<
" --save-distortion" << std::endl
37 <<
" Flag to save the distortion coefficient parameters in the XML file." << std::endl
39 <<
" --record <mode>" << std::endl
40 <<
" Allowed values for mode are:" << std::endl
41 <<
" 0: record all the captures images (continuous mode)," << std::endl
42 <<
" 1: record only images selected by a user click (single shot mode)." << std::endl
43 <<
" Default mode: 0" << std::endl
45 <<
" --no-display" << std::endl
46 <<
" Disable displaying captured images." << std::endl
47 <<
" When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
49 <<
" --help, -h" << std::endl
50 <<
" Print this helper message." << std::endl
52 std::cout <<
"USAGE" << std::endl
53 <<
" Example to visualize images:" << std::endl
54 <<
" " << argv[0] << std::endl
56 <<
" Examples to record a sequence of successive images in 640x480 resolution:" << std::endl
57 <<
" " << argv[0] <<
" --seqname I%04d.png" << std::endl
58 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 0" << std::endl
60 <<
" Examples to record single shot 640x480 images:\n"
61 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1\n"
62 <<
" " << argv[0] <<
" --seqname folder/I%04d.png --record 1" << std::endl
64 <<
" Examples to record single shot 1280x720 images:\n"
65 <<
" " << argv[0] <<
" --seqname I%04d.png --record 1 --width 1280 --height 720" << std::endl
69 std::cout <<
"Error" << std::endl
71 <<
"Unsupported parameter " << argv[
error] << std::endl;
78int main(
int argc,
const char *argv[])
80#if defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_THREADS)
81#ifdef ENABLE_VISP_NAMESPACE
84#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
85 std::shared_ptr<vpDisplay> display;
90 std::string opt_seqname;
91 int opt_record_mode = 0;
93 bool opt_display =
true;
94 unsigned int opt_width = 640;
95 unsigned int opt_height = 480;
96 bool save_distortion =
false;
98 for (
int i = 1;
i < argc;
i++) {
99 if (std::string(argv[i]) ==
"--fps" && i + 1 < argc) {
100 opt_fps = std::atoi(argv[++i]);
102 else if (std::string(argv[i]) ==
"--seqname" && i + 1 < argc) {
103 opt_seqname = std::string(argv[++i]);
105 else if (std::string(argv[i]) ==
"--width" && i + 1 < argc) {
106 opt_width = std::atoi(argv[++i]);
108 else if (std::string(argv[i]) ==
"--height" && i + 1 < argc) {
109 opt_height = std::atoi(argv[++i]);
111 else if (std::string(argv[i]) ==
"--record" && i + 1 < argc) {
112 opt_record_mode = std::atoi(argv[++i]);
114 else if (std::string(argv[i]) ==
"--no-display") {
117 else if (std::string(argv[i]) ==
"--save-distortion") {
118 save_distortion =
true;
120 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
130 if ((!opt_display) && (!opt_seqname.empty())) {
134 if (opt_fps != 6 && opt_fps != 15 && opt_fps != 30 && opt_fps != 60) {
137 std::cout <<
"Resolution : " << opt_width <<
" x " << opt_height << std::endl;
138 std::cout <<
"Recording : " << (opt_seqname.empty() ?
"disabled" :
"enabled") << std::endl;
139 std::cout <<
"Framerate : " << opt_fps << std::endl;
140 std::cout <<
"Display : " << (opt_display ?
"enabled" :
"disabled") << std::endl;
142 std::string text_record_mode =
143 std::string(
"Record mode: ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
145 if (!opt_seqname.empty()) {
146 std::cout << text_record_mode << std::endl;
147 std::cout <<
"Record name: " << opt_seqname << std::endl;
151 std::cout <<
"SDK : Realsense 2" << std::endl;
154 config.disable_stream(RS2_STREAM_DEPTH);
155 config.disable_stream(RS2_STREAM_INFRARED);
156 config.enable_stream(RS2_STREAM_COLOR, opt_width, opt_height, RS2_FORMAT_RGBA8, opt_fps);
161 std::cout <<
"Image size : " << I.getWidth() <<
" " << I.getHeight() << std::endl;
167#
if defined(VISP_HAVE_PUGIXML)
168 if (!opt_seqname.empty()) {
170 std::string output_folder = vpIoTools::getParent(opt_seqname);
171 if (!vpIoTools::checkDirectory(output_folder)) {
173 std::cout <<
"Create output folder: " << output_folder << std::endl;
174 vpIoTools::makeDirectory(output_folder);
176 catch (const vpException &e) {
177 std::cout << e.getStringMessage();
181 std::string cam_filename = output_folder +
"/camera.xml";
183 std::cout <<
"Save camera intrinsics in: " << cam_filename << std::endl;
185 std::cout <<
"Cannot save camera parameters in " << cam_filename << std::endl;
189 std::cout <<
"Warning: Unable to save camera parameters in xml since pugixml 3rdparty is not enabled" << std::endl;
193#if !(defined(VISP_HAVE_DISPLAY))
194 std::cout <<
"No image viewer is available..." << std::endl;
197#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
205 vpImageQueue<vpRGBa> image_queue(opt_seqname, opt_record_mode);
216 quit = image_queue.record(I);
218 std::stringstream ss;
223 image_queue.cancel();
224 image_storage_thread.join();
227 std::cout <<
"Catch an exception: " <<
e << std::endl;
229#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
230 if (display !=
nullptr) {
237#if !defined(VISP_HAVE_REALSENSE2)
238 std::cout <<
"Install librealsense version > 2.31.0, configure and build ViSP again to use this example" << std::endl;
240#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
241 std::cout <<
"This tutorial should be built with c++11 support" << std::endl;
Generic class defining intrinsic camera parameters.
@ perspectiveProjWithDistortion
Perspective projection with distortion model.
@ perspectiveProjWithoutDistortion
Perspective projection without distortion model.
Class that defines generic functionalities for display.
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 emitted by ViSP classes.
Definition of the vpImage class member functions.
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()