disparity-transform.h
Go to the documentation of this file.
1 // Disparity transformation block is responsible to convert stereoscopic depth to disparity data
2 // and vice versa
3 // License: Apache 2.0. See LICENSE file in root directory.
4 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
5 
6 #pragma once
7 
8 #include "../include/librealsense2/hpp/rs_frame.hpp"
9 #include "../include/librealsense2/hpp/rs_processing.hpp"
10 #include "synthetic-stream.h"
11 
12 namespace librealsense
13 {
15  {
16  public:
17  disparity_transform(bool transform_to_disparity);
18  bool should_process(const rs2::frame& frame) override;
20 
21  protected:
23 
24  template<typename Tin, typename Tout>
25  void convert(const void* in_data, void* out_data)
26  {
27  static_assert((std::is_arithmetic<Tin>::value), "disparity transform requires numeric type for input data");
28  static_assert((std::is_arithmetic<Tout>::value), "disparity transform requires numeric type for output data");
29 
30  auto in = reinterpret_cast<const Tin*>(in_data);
31  auto out = reinterpret_cast<Tout*>(out_data);
32 
34  const float round = fp ? 0.5f : 0.f;
35 
36  float input{};
37  //TODO SSE optimize
38  for (size_t i = 0; i < _height; i++)
39  for (size_t j = 0; j < _width; j++)
40  {
41  input = *in;
42  if (std::isnormal(input))
43  *out++ = static_cast<Tout>((_d2d_convert_factor / input)+round);
44  else
45  *out++ = 0;
46  in++;
47  }
48  }
49 
50  private:
52 
53  void on_set_mode(bool to_disparity);
54 
60  float _stereo_baseline_meter; // in meters
61  float _depth_units;
63  size_t _width, _height;
64  size_t _bpp;
65  };
67 
69  {
70  public:
71  struct info {
72  bool stereoscopic_depth = false;
73  float depth_units = 0;
74  float d2d_convert_factor = 0;
75  };
76 
78  {
79  // Check if the new frame originated from stereo-based depth sensor
80  // and retrieve the stereo baseline parameter that will be used in transformations
81  auto snr = ((frame_interface*)f.get())->get_sensor().get();
83  auto info = disparity_info::info();
84  float stereo_baseline_meter;
85 
86  // Playback sensor
87  if (auto a = As<librealsense::extendable_interface>(snr))
88  {
91  {
92  dss = ptr;
94  stereo_baseline_meter = dss->get_stereo_baseline_mm()*0.001f;
95  }
96  }
97  else // Live sensor
98  {
99  info.stereoscopic_depth = Is<librealsense::depth_stereo_sensor>(snr);
101  {
102  dss = As<librealsense::depth_stereo_sensor>(snr);
104  stereo_baseline_meter = dss->get_stereo_baseline_mm()* 0.001f;
105  }
106  }
107 
109  {
110  auto vp = f.get_profile().as<rs2::video_stream_profile>();
111  auto focal_lenght_mm = vp.get_intrinsics().fx;
112  const uint8_t fractional_bits = 5;
113  const uint8_t fractions = 1 << fractional_bits;
114  info.d2d_convert_factor = (stereo_baseline_meter * focal_lenght_mm * fractions) / info.depth_units;
115  }
116 
117  return info;
118  }
119 
120  private:
121  disparity_info() = delete;
122  disparity_info(const disparity_info& other) = delete;
123  };
124 }
void convert(const void *in_data, void *out_data)
disparity_transform(bool transform_to_disparity)
rs2_frame * get() const
Definition: rs_frame.hpp:590
void update_transformation_profile(const rs2::frame &f)
GLfloat value
stream_profile get_profile() const
Definition: rs_frame.hpp:557
rs2::stream_profile _target_stream_profile
unsigned char uint8_t
Definition: stdint.h:78
bool should_process(const rs2::frame &frame) override
rs2::stream_profile _source_stream_profile
GLboolean GLboolean GLboolean GLboolean a
static info update_info_from_frame(const rs2::frame &f)
def info(name, value, persistent=False)
Definition: test.py:301
virtual float get_depth_scale() const =0
GLdouble f
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
virtual float get_stereo_baseline_mm() const =0
GLint j
rs2_intrinsics get_intrinsics() const
Definition: rs_frame.hpp:238
rs2::frame prepare_target_frame(const rs2::frame &f, const rs2::frame_source &source)
GLenum GLenum GLenum input
Definition: glext.h:10805
GLuint in
Definition: glext.h:8859
GLsizei GLsizei GLchar * source
int i
MAP_EXTENSION(RS2_EXTENSION_POINTS, librealsense::points)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:12