File: tutorial-grabber-rgbd-D435-structurecore.cpp

package info (click to toggle)
visp 3.7.0-7
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 166,380 kB
  • sloc: cpp: 392,705; ansic: 224,448; xml: 23,444; python: 13,701; java: 4,792; sh: 206; objc: 145; makefile: 118
file content (87 lines) | stat: -rw-r--r-- 3,649 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*! \example tutorial-grabber-rgbd-D435-structurecore.cpp */
#include <iostream>

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImageConvert.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/sensor/vpOccipitalStructure.h>
#include <visp3/sensor/vpRealSense2.h>

/*!
 * Grab color and depth images from Intel RealSense D435 and Occipital Structure Core sensors.
 */
int main()
{
#if defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_OCCIPITAL_STRUCTURE) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
#ifdef ENABLE_VISP_NAMESPACE
  using namespace VISP_NAMESPACE_NAME;
#endif
  // Both cameras can stream color and depth in 640x480 resolution.
  unsigned int width = 640, height = 480;

  // Grabbers.
  vpRealSense2 rs;
  vpOccipitalStructure sc;

  // 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);

  std::shared_ptr<vpDisplay> d_rs_depth = vpDisplayFactory::createDisplay(I_depth_rs, 10, height + 10, "RealSense Depth");
  std::shared_ptr<vpDisplay> d_sc_depth = vpDisplayFactory::createDisplay(I_depth_sc, width + 10, height + 10, "Structure Core Depth");
  std::shared_ptr<vpDisplay> d_color_rs = vpDisplayFactory::createDisplay(I_color_rs, 10, 10, "RealSense Color");
  std::shared_ptr<vpDisplay> d_color_sc = vpDisplayFactory::createDisplay(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);
  rs.open(cfg);

  // 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.
  sc.open(settings);

  // 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);

    vpDisplay::display(I_color_rs);
    vpDisplay::display(I_color_sc);
    vpDisplay::display(I_depth_rs);
    vpDisplay::display(I_depth_sc);

    vpDisplay::flush(I_color_rs);
    vpDisplay::flush(I_color_sc);
    vpDisplay::flush(I_depth_rs);
    vpDisplay::flush(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)) {
      break;
    }
  }
#else
#if !(defined(VISP_HAVE_OCCIPITAL_STRUCTURE))
  std::cout << "Install libStructure, configure and build ViSP again to use this example" << std::endl;
#endif
#if !(defined(VISP_HAVE_REALSENSE2))
  std::cout << "Install librealsense, 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
}