Visual Servoing Platform  version 3.6.1 under development (2023-12-01)
#include <iostream>
#include <visp3/core/vpImageConvert.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/sensor/vpOccipitalStructure.h>
#include <visp3/sensor/vpRealSense2.h>
int main(int argc, char **argv)
// Both cameras can stream color and depth in 640x480 resolution.
unsigned int width = 640, height = 480;
// Grabbers.
// Required images to acquire and display color and depth.
vpImage<float> sc_I_depth_raw(height, width);
vpImage<uint16_t> rs_I_depth_raw(height, width);
vpImage<vpRGBa> I_depth_sc(height, width), I_depth_rs(height, width);
vpImage<vpRGBa> I_color_sc(height, width), I_color_rs(height, width);
vpDisplayX d_rs_depth(I_depth_rs, 10, height + 10, "RealSense Depth"),
d_sc_depth(I_depth_sc, width + 10, height + 10, "Structure Core Depth");
vpDisplayX d_color_rs(I_color_rs, 10, 10, "RealSense Color"),
d_color_sc(I_color_sc, width + 10, 10, "Structure Core Color");
// Configuring and opening RealSense grabber.
rs2::config cfg;
cfg.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, 30);
cfg.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16, 30);;
// Configuring and opening Structure Core grabber.
ST::CaptureSessionSettings settings;
settings.source = ST::CaptureSessionSourceId::StructureCore;
settings.structureCore.visibleEnabled = true;
settings.applyExpensiveCorrection = true; // Apply a correction and clean filter to the depth before streaming.;
// Acquiring images.
for (;;) {
rs.acquire(reinterpret_cast<unsigned char *>(I_color_rs.bitmap),
reinterpret_cast<unsigned char *>(rs_I_depth_raw.bitmap), nullptr, nullptr, nullptr, nullptr, nullptr);
sc.acquire(reinterpret_cast<unsigned char *>(I_color_sc.bitmap),
reinterpret_cast<unsigned char *>(sc_I_depth_raw.bitmap));
// Converting raw depth data to color images.
vpImageConvert::createDepthHistogram(rs_I_depth_raw, I_depth_rs);
vpImageConvert::createDepthHistogram(sc_I_depth_raw, I_depth_sc);
if (vpDisplay::getClick(I_color_rs, false) || vpDisplay::getClick(I_color_sc, false) ||
vpDisplay::getClick(I_depth_rs, false) || vpDisplay::getClick(I_depth_sc, false)) {
std::cout << "Install libStructure, configure and build ViSP again to use this example" << std::endl;
#if !(defined(VISP_HAVE_REALSENSE2))
std::cout << "Install librealsense, configure and build ViSP again to use this example" << std::endl;
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:128
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)
Type * bitmap
points toward the bitmap
Definition: vpImage.h:139
void acquire(vpImage< unsigned char > &gray, bool undistorted=false, double *ts=nullptr)
bool open(const ST::CaptureSessionSettings &settings)
void acquire(vpImage< unsigned char > &grey, double *ts=nullptr)
bool open(const rs2::config &cfg=rs2::config())