hole-filling-filter.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2018 Intel Corporation. All Rights Reserved
3 // Enhancing the input video frame by filling missing data.
4 #pragma once
5 
6 namespace librealsense
7 {
9  {
14  };
15 
17  {
18  public:
20 
21  protected:
22  void update_configuration(const rs2::frame& f);
23  rs2::frame process_frame(const rs2::frame_source& source, const rs2::frame& f) override;
24 
26 
27  template<typename T>
29  {
31  T* data = reinterpret_cast<T*>(image_data);
32 
33  // Select and apply the appropriate hole filling method
34  switch (_hole_filling_mode)
35  {
36  case hf_fill_from_left:
38  break;
41  break;
44  break;
45  default:
47  << "Unsupported hole filling mode: " << _hole_filling_mode << " is out of range.");
48  }
49  }
50 
51  // Implementations of the hole-filling methods
52  template<typename T>
53  inline void holes_fill_left(T* image_data, size_t width, size_t height, size_t stride)
54  {
55  std::function<bool(T*)> fp_oper = [](T* ptr) { return !*((int *)ptr); };
56  std::function<bool(T*)> uint_oper = [](T* ptr) { return !(*ptr); };
57  auto empty = (std::is_floating_point<T>::value) ? fp_oper : uint_oper;
58 
59  T* p = image_data;
60 
61  for (size_t j = 0; j < height; ++j)
62  {
63  ++p;
64  for (size_t i = 1; i < width; ++i)
65  {
66  if (empty(p))
67  *p = *(p - 1);
68  ++p;
69  }
70  }
71  }
72 
73  template<typename T>
74  inline void holes_fill_farest(T* image_data, size_t width, size_t height, size_t stride)
75  {
76  std::function<bool(T*)> fp_oper = [](T* ptr) { return !*((int *)ptr); };
77  std::function<bool(T*)> uint_oper = [](T* ptr) { return !(*ptr); };
78  auto empty = (std::is_floating_point<T>::value) ? fp_oper : uint_oper;
79 
80  T tmp = 0;
81  T * p = image_data + width;
82  T * q = nullptr;
83  for (int j = 1; j < height - 1; ++j)
84  {
85  ++p;
86  for (size_t i = 1; i < width; ++i)
87  {
88  if (empty(p))
89  {
90  tmp = *(p - width);
91 
92  q = p - width - 1;
93  if (*q > tmp)
94  tmp = *q;
95 
96  q = p - 1;
97  if (*q > tmp)
98  tmp = *q;
99 
100  q = p + width - 1;
101  if (*q > tmp)
102  tmp = *q;
103 
104  q = p + width;
105  if (*q > tmp)
106  tmp = *q;
107 
108  *p = tmp;
109  }
110 
111  p++;
112  }
113  }
114  }
115 
116  template<typename T>
117  inline void holes_fill_nearest(T* image_data, size_t width, size_t height, size_t stride)
118  {
119  std::function<bool(T*)> fp_oper = [](T* ptr) { return !*((int *)ptr); };
120  std::function<bool(T*)> uint_oper = [](T* ptr) { return !(*ptr); };
121  auto empty = (std::is_floating_point<T>::value) ? fp_oper : uint_oper;
122 
123  T tmp = 0;
124  T * p = image_data + width;
125  T * q = nullptr;
126  for (int j = 1; j < height - 1; ++j)
127  {
128  ++p;
129  for (size_t i = 1; i < width; ++i)
130  {
131  if (empty(p))
132  {
133  tmp = *(p - width);
134 
135  q = p - width - 1;
136  if (!empty(q) && (*q < tmp))
137  tmp = *q;
138 
139  q = p - 1;
140  if (!empty(q) && (*q < tmp))
141  tmp = *q;
142 
143  q = p + width - 1;
144  if (!empty(q) && (*q < tmp))
145  tmp = *q;
146 
147  q = p + width;
148  if (!empty(q) && (*q < tmp))
149  tmp = *q;
150 
151  *p = tmp;
152  }
153 
154  p++;
155  }
156  }
157  }
158 
159  private:
160 
162  size_t _bpp;
163  rs2_extension _extension_type; // Strictly Depth/Disparity
168  };
170 }
GLfloat GLfloat p
Definition: glext.h:12687
GLfloat value
unsigned char uint8_t
Definition: stdint.h:78
void update_configuration(const rs2::frame &f)
void holes_fill_nearest(T *image_data, size_t width, size_t height, size_t stride)
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
GLdouble f
GLint GLsizei GLsizei height
GLint j
GLdouble GLdouble GLint stride
void holes_fill_farest(T *image_data, size_t width, size_t height, size_t stride)
rs2::frame prepare_target_frame(const rs2::frame &f, const rs2::frame_source &source)
GLdouble GLdouble GLdouble q
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
Definition: rs_types.h:166
void apply_hole_filling(void *image_data)
GLsizei GLsizei GLchar * source
int i
Definition: parser.hpp:150
MAP_EXTENSION(RS2_EXTENSION_POINTS, librealsense::points)
GLint GLsizei width
void holes_fill_left(T *image_data, size_t width, size_t height, size_t stride)
std::string to_string(T value)


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