Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-grabber-rgbd-D435-structurecore.cpp
1
2#include <iostream>
3
4#include <visp3/core/vpImageConvert.h>
5#include <visp3/gui/vpDisplayGDI.h>
6#include <visp3/gui/vpDisplayX.h>
7#include <visp3/sensor/vpOccipitalStructure.h>
8#include <visp3/sensor/vpRealSense2.h>
9
13int main(int argc, char **argv)
14{
15#if defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_OCCIPITAL_STRUCTURE) && \
16 (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
17 // Both cameras can stream color and depth in 640x480 resolution.
18 unsigned int width = 640, height = 480;
19
20 // Grabbers.
21 vpRealSense2 rs;
23
24 // Required images to acquire and display color and depth.
25 vpImage<float> sc_I_depth_raw(height, width);
26 vpImage<uint16_t> rs_I_depth_raw(height, width);
27 vpImage<vpRGBa> I_depth_sc(height, width), I_depth_rs(height, width);
28 vpImage<vpRGBa> I_color_sc(height, width), I_color_rs(height, width);
29
30 vpDisplayX d_rs_depth(I_depth_rs, 10, height + 10, "RealSense Depth"),
31 d_sc_depth(I_depth_sc, width + 10, height + 10, "Structure Core Depth");
32 vpDisplayX d_color_rs(I_color_rs, 10, 10, "RealSense Color"),
33 d_color_sc(I_color_sc, width + 10, 10, "Structure Core Color");
34
35 // Configuring and opening RealSense grabber.
36 rs2::config cfg;
37 cfg.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, 30);
38 cfg.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16, 30);
39 rs.open(cfg);
40
41 // Configuring and opening Structure Core grabber.
42 ST::CaptureSessionSettings settings;
43 settings.source = ST::CaptureSessionSourceId::StructureCore;
44 settings.structureCore.visibleEnabled = true;
45 settings.applyExpensiveCorrection = true; // Apply a correction and clean filter to the depth before streaming.
46 sc.open(settings);
47
48 // Acquiring images.
49 for (;;) {
50 rs.acquire(reinterpret_cast<unsigned char *>(I_color_rs.bitmap),
51 reinterpret_cast<unsigned char *>(rs_I_depth_raw.bitmap), NULL, NULL, NULL, NULL, NULL);
52 sc.acquire(reinterpret_cast<unsigned char *>(I_color_sc.bitmap),
53 reinterpret_cast<unsigned char *>(sc_I_depth_raw.bitmap));
54
55 // Converting raw depth data to color images.
56 vpImageConvert::createDepthHistogram(rs_I_depth_raw, I_depth_rs);
57 vpImageConvert::createDepthHistogram(sc_I_depth_raw, I_depth_sc);
58
59 vpDisplay::display(I_color_rs);
60 vpDisplay::display(I_color_sc);
61 vpDisplay::display(I_depth_rs);
62 vpDisplay::display(I_depth_sc);
63
64 vpDisplay::flush(I_color_rs);
65 vpDisplay::flush(I_color_sc);
66 vpDisplay::flush(I_depth_rs);
67 vpDisplay::flush(I_depth_sc);
68
69 if (vpDisplay::getClick(I_color_rs, false) || vpDisplay::getClick(I_color_sc, false) ||
70 vpDisplay::getClick(I_depth_rs, false) || vpDisplay::getClick(I_depth_sc, false)) {
71 break;
72 }
73 }
74#else
75 (void)argc;
76 (void)argv;
77#if !(defined(VISP_HAVE_OCCIPITAL_STRUCTURE))
78 std::cout << "Install libStructure, configure and build ViSP again to use this example" << std::endl;
79#endif
80#if !(defined(VISP_HAVE_REALSENSE2))
81 std::cout << "Install librealsense, configure and build ViSP again to use this example" << std::endl;
82#endif
83#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
84 std::cout << "This tutorial should be built with c++11 support" << std::endl;
85#endif
86#endif
87}
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:132
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void createDepthHistogram(const vpImage< uint16_t > &src_depth, vpImage< vpRGBa > &dest_rgba)
Definition of the vpImage class member functions.
Definition vpImage.h:135
void acquire(vpImage< unsigned char > &gray, bool undistorted=false, double *ts=NULL)
bool open(const ST::CaptureSessionSettings &settings)
void acquire(vpImage< unsigned char > &grey, double *ts=NULL)
bool open(const rs2::config &cfg=rs2::config())