2 #include <visp3/core/vpConfig.h>
3 #include <visp3/core/vpImage.h>
4 #include <visp3/gui/vpDisplayFactory.h>
5 #include <visp3/io/vpImageStorageWorker.h>
6 #include <visp3/sensor/vpOccipitalStructure.h>
8 void usage(
const char *argv[],
int error)
10 std::cout <<
"SYNOPSIS" << std::endl
11 <<
" " << argv[0] <<
" [--depth-fps <6|15|30|60>]"
12 <<
" [--depth-fps <6|15|30|60>]"
14 <<
" [--no-frame-sync]"
15 <<
" [--record <mode>]"
17 <<
" [--help] [-h]" << std::endl
19 std::cout <<
"DESCRIPTION" << std::endl
20 <<
" --visible-fps <6|15|30|60>" << std::endl
21 <<
" Visible camera (gray or color) frames per second." << std::endl
22 <<
" Default: 30." << std::endl
24 <<
" --depth-fps <6|15|30|60>" << std::endl
25 <<
" Depth camera frames per second." << std::endl
26 <<
" Default: 30." << std::endl
28 <<
" --sxga" << std::endl
29 <<
" If available, output 1280x960 high resolution depth array." << std::endl
31 <<
" --no-frame-sync" << std::endl
32 <<
" If available, disable frame synchronization." << std::endl
34 <<
" --record <mode>" << std::endl
35 <<
" Allowed values for mode are:" << std::endl
36 <<
" 0: record all the captures images (continuous mode)," << std::endl
37 <<
" 1: record only images selected by a user click (single shot mode)." << std::endl
38 <<
" Default mode: 0" << std::endl
40 <<
" --no-display" << std::endl
41 <<
" Disable displaying captured images." << std::endl
42 <<
" When used and sequence name specified, record mode is internally set to 1 (continuous mode)."
45 <<
" --help, -h" << std::endl
46 <<
" Print this helper message." << std::endl
48 std::cout <<
"USAGE" << std::endl
49 <<
" Example to visualize images:" << std::endl
50 <<
" " << argv[0] << std::endl
52 <<
" Example to record a sequence of images:" << std::endl
53 <<
" " << argv[0] <<
" --record 0" << std::endl
55 <<
" Example to record a sequence of images at different frame rates:" << std::endl
56 <<
" " << argv[0] <<
" --record 0 --depth-fps 15 --visible-fps 10 --no-frame-sync" << std::endl
58 <<
" Example to record single shot images:\n"
59 <<
" " << argv[0] <<
" --record 1" << std::endl
63 std::cout <<
"Error" << std::endl
65 <<
"Unsupported parameter " << argv[error] << std::endl;
72 int main(
int argc,
const char *argv[])
74 #if defined(VISP_HAVE_OCCIPITAL_STRUCTURE) && defined(VISP_HAVE_THREADS)
75 #ifdef ENABLE_VISP_NAMESPACE
78 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
79 std::shared_ptr<vpDisplay> display_visible;
80 std::shared_ptr<vpDisplay> display_depth;
86 std::string opt_seqname_visible =
"visible-%04d.png", opt_seqname_depth =
"depth-%04d.png";
87 int opt_record_mode = 0;
88 int opt_depth_fps = 30, opt_visible_fps = opt_depth_fps;
89 bool opt_sxga =
false;
90 bool opt_frame_sync =
true;
91 bool opt_display =
true;
93 for (
int i = 1; i < argc; i++) {
94 if (std::string(argv[i]) ==
"--depth-fps" && i + 1 < argc) {
95 opt_depth_fps = std::atoi(argv[++i]);
97 else if (std::string(argv[i]) ==
"--visible-fps" && i + 1 < argc) {
98 opt_visible_fps = std::atoi(argv[++i]);
100 else if (std::string(argv[i]) ==
"--sxga") {
103 else if (std::string(argv[i]) ==
"--no-frame-sync") {
104 opt_frame_sync =
false;
106 else if (std::string(argv[i]) ==
"--record" && i + 1 < argc) {
107 opt_record_mode = std::atoi(argv[++i]);
109 else if (std::string(argv[i]) ==
"--no-display") {
112 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
126 std::cout <<
"Depth framerate : " << opt_depth_fps << std::endl;
127 std::cout <<
"Visible framerate: " << opt_visible_fps << std::endl;
128 std::cout <<
"Display : " << (opt_display ?
"enabled" :
"disabled") << std::endl;
130 std::string text_record_mode =
131 std::string(
"Record mode: ") + (opt_record_mode ? std::string(
"single") : std::string(
"continuous"));
133 std::cout << text_record_mode << std::endl;
134 std::cout <<
"Visible record name: " << opt_seqname_visible << std::endl;
135 std::cout <<
"Depth record name: " << opt_seqname_depth << std::endl;
144 if (opt_visible_fps < 2) {
148 ST::CaptureSessionSettings settings;
149 settings.source = ST::CaptureSessionSourceId::StructureCore;
150 settings.structureCore.visibleEnabled =
true;
151 settings.frameSyncEnabled = opt_frame_sync;
152 settings.structureCore.depthFramerate = opt_depth_fps;
153 settings.structureCore.visibleFramerate = opt_visible_fps;
155 settings.structureCore.depthResolution = ST::StructureCoreDepthResolution::SXGA;
156 settings.applyExpensiveCorrection =
true;
158 bool is_open = g.
open(settings);
168 #if !(defined(VISP_HAVE_DISPLAY))
169 std::cout <<
"No image viewer is available..." << std::endl;
172 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
182 vpImageQueue<vpRGBa> image_queue_visible(opt_seqname_visible, opt_record_mode);
183 std::thread image_visible_storage_thread;
188 vpImageQueue<vpRGBa> image_queue_depth(opt_seqname_depth, opt_record_mode);
203 quit = image_queue_visible.record(I_color);
204 quit |= image_queue_depth.record(I_depth,
nullptr, image_queue_visible.getRecordingTrigger(),
true);
206 std::stringstream ss;
212 image_queue_visible.cancel();
213 image_queue_depth.cancel();
214 image_visible_storage_thread.join();
215 image_depth_storage_thread.join();
219 std::cout <<
"Catch an exception: " << e << std::endl;
221 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
222 if (display_visible !=
nullptr) {
223 delete display_visible;
225 if (display_depth !=
nullptr) {
226 delete display_depth;
232 #if !(defined(VISP_HAVE_OCCIPITAL_STRUCTURE))
233 std::cout <<
"Install libStructure, configure and build ViSP again to use this example" << std::endl;
235 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
236 std::cout <<
"This tutorial should be built with c++11 support" << std::endl;
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.
static void createDepthHistogram(const vpImage< uint16_t > &src_depth, vpImage< vpRGBa > &dest_rgba)
unsigned int getWidth() const
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
unsigned int getHeight(vpOccipitalStructureStream stream_type)
void acquire(vpImage< unsigned char > &gray, bool undistorted=false, double *ts=nullptr)
unsigned int getWidth(vpOccipitalStructureStream stream_type)
bool open(const ST::CaptureSessionSettings &settings)
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 int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()