2 #include <visp3/core/vpConfig.h>
3 #include <visp3/core/vpImage.h>
4 #include <visp3/gui/vpDisplayGDI.h>
5 #include <visp3/gui/vpDisplayOpenCV.h>
6 #include <visp3/gui/vpDisplayX.h>
7 #include <visp3/io/vpImageStorageWorker.h>
8 #include <visp3/sensor/vpRealSense2.h>
10 void usage(
const char *argv[],
int error)
12 std::cout <<
"SYNOPSIS" << std::endl
13 <<
" " << argv[0] <<
" [--fps <6|15|30|60>]"
14 <<
" [--record <mode>]"
16 <<
" [--help] [-h]" << std::endl
18 std::cout <<
"DESCRIPTION" << std::endl
19 <<
" --fps <6|15|30|60>" << std::endl
20 <<
" Frames per second." << std::endl
21 <<
" Default: 30." << std::endl
23 <<
" --record <mode>" << std::endl
24 <<
" Allowed values for mode are:" << std::endl
25 <<
" 0: record all the captures images (continuous mode)," << std::endl
26 <<
" 1: record only images selected by a user click (single shot mode)." << std::endl
27 <<
" Default mode: 0" << std::endl
29 <<
" --no-display" << std::endl
30 <<
" Disable displaying captured images." << std::endl
31 <<
" When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
34 <<
" --help, -h" << std::endl
35 <<
" Print this helper message." << std::endl
37 std::cout <<
"USAGE" << std::endl
38 <<
" Example to visualize images:" << std::endl
39 <<
" " << argv[0] << std::endl
41 <<
" Example to record a sequence of images:" << std::endl
42 <<
" " << argv[0] <<
" --record 0" << std::endl
44 <<
" Example to record single shot images:\n"
45 <<
" " << argv[0] <<
" --record 1" << std::endl
49 std::cout <<
"Error" << std::endl
51 <<
"Unsupported parameter " << argv[error] << std::endl;
58 int main(
int argc,
const char *argv[])
60 #if defined(VISP_HAVE_REALSENSE2) && (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0)) && defined(VISP_HAVE_THREADS)
61 #ifdef ENABLE_VISP_NAMESPACE
65 std::string opt_seqname_left =
"left-%04d.png", opt_seqname_right =
"right-%04d.png";
66 int opt_record_mode = 0;
68 bool opt_display =
true;
70 for (
int i = 1; i < argc; i++) {
71 if (std::string(argv[i]) ==
"--fps") {
72 opt_fps = std::atoi(argv[i + 1]);
75 else if (std::string(argv[i]) ==
"--record") {
76 opt_record_mode = std::atoi(argv[i + 1]);
79 else if (std::string(argv[i]) ==
"--no-display") {
82 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
96 std::cout <<
"Framerate : " << opt_fps << std::endl;
97 std::cout <<
"Display : " << (opt_display ?
"enabled" :
"disabled") << std::endl;
99 std::string text_record_mode =
100 std::string(
"Record mode: ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
102 std::cout << text_record_mode << std::endl;
103 std::cout <<
"Left record name: " << opt_seqname_left << std::endl;
104 std::cout <<
"Right record name: " << opt_seqname_right << std::endl;
110 config.enable_stream(RS2_STREAM_FISHEYE, 1);
111 config.enable_stream(RS2_STREAM_FISHEYE, 2);
116 std::cout <<
"Image size : " << I_left.
getWidth() <<
" " << I_right.
getHeight() << std::endl;
118 vpDisplay *display_left =
nullptr, *display_right =
nullptr;
120 #if !(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
121 std::cout <<
"No image viewer is available..." << std::endl;
127 display_left =
new vpDisplayX(I_left, 10, 10,
"Left image");
128 display_right =
new vpDisplayX(I_right, I_left.
getWidth(), 10,
"Right image");
129 #elif defined(VISP_HAVE_GDI)
130 display_left =
new vpDisplayGDI(I_left, 10, 10,
"Left image");
132 #elif defined(HAVE_OPENCV_HIGHGUI)
138 vpImageQueue<unsigned char> image_queue_left(opt_seqname_left, opt_record_mode);
139 vpImageQueue<unsigned char> image_queue_right(opt_seqname_right, opt_record_mode);
154 quit = image_queue_left.record(I_left);
155 quit |= image_queue_right.record(I_right,
nullptr, image_queue_left.getRecordingTrigger(),
true);
157 std::stringstream ss;
163 image_queue_left.cancel();
164 image_queue_right.cancel();
165 image_left_storage_thread.join();
166 image_right_storage_thread.join();
172 delete display_right;
176 std::cout <<
"Catch an exception: " << e << std::endl;
181 #if !(defined(VISP_HAVE_REALSENSE2) && (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0)))
182 std::cout <<
"Install librealsense version > 2.31.0, configure and build ViSP again to use this example" << std::endl;
184 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
185 std::cout <<
"This tutorial should be built with c++11 support" << std::endl;
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
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.
unsigned int getWidth() const
unsigned int getHeight() const
void acquire(vpImage< unsigned char > &grey, double *ts=nullptr)
bool open(const rs2::config &cfg=rs2::config())
VISP_EXPORT double measureTimeMs()