#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImage.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/io/vpImageStorageWorker.h>
#include <visp3/sensor/vpRealSense2.h>
void usage(const char *argv[], int error)
{
std::cout << "SYNOPSIS" << std::endl
<< " " << argv[0] << " [--fps <6|15|30|60>]"
<< " [--record <mode>]"
<< " [--no-display]"
<< " [--help] [-h]" << std::endl
<< std::endl;
std::cout << "DESCRIPTION" << std::endl
<< " --fps <6|15|30|60>" << std::endl
<< " Frames per second." << std::endl
<< " Default: 30." << std::endl
<< std::endl
<< " --record <mode>" << std::endl
<< " Allowed values for mode are:" << std::endl
<< " 0: record all the captures images (continuous mode)," << std::endl
<< " 1: record only images selected by a user click (single shot mode)." << std::endl
<< " Default mode: 0" << std::endl
<< std::endl
<< " --no-display" << std::endl
<< " Disable displaying captured images." << std::endl
<< " When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
<< std::endl
<< std::endl
<< " --help, -h" << std::endl
<< " Print this helper message." << std::endl
<< std::endl;
std::cout << "USAGE" << std::endl
<< " Example to visualize images:" << std::endl
<< " " << argv[0] << std::endl
<< std::endl
<< " Example to record a sequence of images:" << std::endl
<< " " << argv[0] << " --record 0" << std::endl
<< std::endl
<< " Example to record single shot images:\n"
<< " " << argv[0] << " --record 1" << std::endl
<< std::endl;
if (error) {
std::cout << "Error" << std::endl
<< " "
<< "Unsupported parameter " << argv[error] << std::endl;
}
}
int main(int argc, const char *argv[])
{
#if defined(VISP_HAVE_REALSENSE2) && (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0)) && defined(VISP_HAVE_THREADS)
#ifdef ENABLE_VISP_NAMESPACE
#endif
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
std::shared_ptr<vpDisplay> display_left;
std::shared_ptr<vpDisplay> display_right;
#else
#endif
try {
std::string opt_seqname_left = "left-%04d.png", opt_seqname_right = "right-%04d.png";
int opt_record_mode = 0;
int opt_fps = 30;
bool opt_display = true;
for (int i = 1; i < argc; i++) {
if (std::string(argv[i]) == "--fps" && i + 1 < argc) {
opt_fps = std::atoi(argv[++i]);
}
else if (std::string(argv[i]) == "--record" && i + 1 < argc) {
opt_record_mode = std::atoi(argv[++i]);
}
else if (std::string(argv[i]) == "--no-display") {
opt_display = false;
}
else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
usage(argv, 0);
return EXIT_SUCCESS;
}
else {
usage(argv, i);
return EXIT_FAILURE;
}
}
if (!opt_display) {
opt_record_mode = 0;
}
std::cout << "Framerate : " << opt_fps << std::endl;
std::cout << "Display : " << (opt_display ? "enabled" : "disabled") << std::endl;
std::string text_record_mode =
std::string("Record mode: ") + (opt_record_mode ? std::string("single") : std::string("continuous"));
std::cout << text_record_mode << std::endl;
std::cout << "Left record name: " << opt_seqname_left << std::endl;
std::cout << "Right record name: " << opt_seqname_right << std::endl;
rs2::config config;
config.enable_stream(RS2_STREAM_FISHEYE, 1);
config.enable_stream(RS2_STREAM_FISHEYE, 2);
std::cout <<
"Image size : " << I_left.
getWidth() <<
" " << I_right.
getHeight() << std::endl;
if (opt_display) {
#if !(defined(VISP_HAVE_DISPLAY))
std::cout << "No image viewer is available..." << std::endl;
opt_display = false;
#else
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
#else
#endif
#endif
}
vpImageQueue<unsigned char> image_queue_left(opt_seqname_left, opt_record_mode);
vpImageQueue<unsigned char> image_queue_right(opt_seqname_right, opt_record_mode);
bool quit = false;
while (!quit) {
quit = image_queue_left.record(I_left);
quit |= image_queue_right.record(I_right, nullptr, image_queue_left.getRecordingTrigger(), true);
std::stringstream ss;
}
image_queue_left.cancel();
image_queue_right.cancel();
image_left_storage_thread.join();
image_right_storage_thread.join();
}
std::cout << "Catch an exception: " << e << std::endl;
}
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
if (display_left != nullptr) {
delete display_left;
}
if (display_right != nullptr) {
delete display_right;
}
#endif
#else
(void)argc;
(void)argv;
#if !(defined(VISP_HAVE_REALSENSE2) && (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0)))
std::cout << "Install librealsense version > 2.31.0, configure and build ViSP again to use this example" << std::endl;
#endif
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
std::cout << "This tutorial should be built with c++11 support" << std::endl;
#endif
#endif
}
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())
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()