temporal-filter.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 #include "types.h"
6 
7 namespace librealsense
8 {
9  const size_t PRESISTENCY_LUT_SIZE = 256;
10 
12  {
13  public:
15 
16  protected:
17  void update_configuration(const rs2::frame& f);
18  rs2::frame process_frame(const rs2::frame_source& source, const rs2::frame& f) override;
19 
21 
22  template<typename T>
23  void temp_jw_smooth(void* frame_data, void * _last_frame_data, uint8_t *history)
24  {
25  static_assert((std::is_arithmetic<T>::value), "temporal filter assumes numeric types");
26 
27  const bool fp = (std::is_floating_point<T>::value);
28 
29  T delta_z = static_cast<T>(_delta_param);
30 
31  auto frame = reinterpret_cast<T*>(frame_data);
32  auto _last_frame = reinterpret_cast<T*>(_last_frame_data);
33 
34  unsigned char mask = 1 << _cur_frame_index;
35 
36  // pass one -- go through image and update all
37  for (size_t i = 0; i < _current_frm_size_pixels; i++)
38  {
39  T cur_val = frame[i];
40  T prev_val = _last_frame[i];
41 
42  if (cur_val)
43  {
44  if (!prev_val)
45  {
46  _last_frame[i] = cur_val;
47  history[i] = mask;
48  }
49  else
50  { // old and new val
51  T diff = static_cast<T>(fabs(cur_val - prev_val));
52 
53  if (diff < delta_z)
54  { // old and new val agree
55  history[i] |= mask;
56  float filtered = _alpha_param * cur_val + _one_minus_alpha * prev_val;
57  T result = static_cast<T>(filtered);
58  frame[i] = result;
59  _last_frame[i] = result;
60  }
61  else
62  {
63  _last_frame[i] = cur_val;
64  history[i] = mask;
65  }
66  }
67  }
68  else
69  { // no cur_val
70  if (prev_val)
71  { // only case we can help
72  unsigned char hist = history[i];
73  unsigned char classification = _persistence_map[hist];
74  if (classification & mask)
75  { // we have had enough samples lately
76  frame[i] = prev_val;
77  }
78  }
79  history[i] &= ~mask;
80  }
81  }
82 
83  _cur_frame_index = (_cur_frame_index + 1) % 8; // at end of cycle
84  }
85 
86  private:
88  void on_set_alpha(float val);
89  void on_set_delta(float val);
90 
93 
94  float _alpha_param; // The normalized weight of the current pixel
96  uint8_t _delta_param; // A threshold when a filter is invoked
98  size_t _bpp;
99  rs2_extension _extension_type; // Strictly Depth/Disparity
103  std::vector<uint8_t> _last_frame; // Hold the last frame received for the current profile
104  std::vector<uint8_t> _history; // represents the history over the last 8 frames, 1 bit per frame
106  // encodes whether a particular 8 bit history is good enough for all 8 phases of storage
107  std::array<uint8_t, PRESISTENCY_LUT_SIZE> _persistence_map;
108  };
110 }
GLfloat value
GLint GLuint mask
rs2::stream_profile _target_stream_profile
void on_set_persistence_control(uint8_t val)
dictionary frame_data
Definition: t265_stereo.py:80
std::array< uint8_t, PRESISTENCY_LUT_SIZE > _persistence_map
unsigned char uint8_t
Definition: stdint.h:78
GLuint GLfloat * val
GLdouble f
std::vector< uint8_t > _history
rs2::stream_profile _source_stream_profile
std::vector< uint8_t > _last_frame
void temp_jw_smooth(void *frame_data, void *_last_frame_data, uint8_t *history)
void update_configuration(const rs2::frame &f)
rs2::frame prepare_target_frame(const rs2::frame &f, const rs2::frame_source &source)
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
Definition: rs_types.h:166
const size_t PRESISTENCY_LUT_SIZE
GLsizei GLsizei GLchar * source
int i
GLuint64EXT * result
Definition: glext.h:10921
MAP_EXTENSION(RS2_EXTENSION_POINTS, librealsense::points)
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override


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