DepthColorizer.cpp
Go to the documentation of this file.
1 #include "DepthColorizer.h"
2 #include "PCH.h"
3 #include "ColorMap.inl"
4 
5 namespace rs2_utils {
6 
7 void make_equalized_histogram(depth_pixel* dst, const rs2::video_frame& depth, const color_map& cm)
8 {
10 
11  const size_t max_depth = 0x10000;
12  static size_t histogram[max_depth];
13  memset(histogram, 0, sizeof(histogram));
14 
15  const auto w = depth.get_width(), h = depth.get_height();
16  const auto depth_data = (const uint16_t*)depth.get_data();
17 
18  for (auto i = 0; i < w*h; ++i) ++histogram[depth_data[i]];
19  for (auto i = 2; i < max_depth; ++i) histogram[i] += histogram[i - 1];
20 
21  const auto scale = 1.0f / (float)histogram[0xFFFF];
22 
23  for (auto i = 0; i < w*h; ++i)
24  {
25  const auto d = depth_data[i];
26  if (d)
27  {
28  //auto f = histogram[d] / (float)histogram[0xFFFF];
29  const auto f = histogram[d] * scale;
30  const auto c = cm.get(f);
31 
32  dst->r = (uint8_t)c.x;
33  dst->g = (uint8_t)c.y;
34  dst->b = (uint8_t)c.z;
35  dst->a = 255;
36  }
37  else
38  {
39  dst->r = 0;
40  dst->g = 0;
41  dst->b = 0;
42  dst->a = 255;
43  }
44  dst++;
45  }
46 }
47 
48 void make_value_cropped_frame(depth_pixel* dst, const rs2::video_frame& depth, const color_map& cm, float depth_min, float depth_max, float depth_units)
49 {
51 
52  const auto scale = 1.0f / (depth_max - depth_min);
53  const auto w = depth.get_width(), h = depth.get_height();
54  const auto depth_data = (const uint16_t*)depth.get_data();
55 
56  for (auto i = 0; i < w*h; ++i)
57  {
58  const auto d = depth_data[i];
59  if (d)
60  {
61  //const auto f = (d * depth_units - depth_min) / (depth_max - depth_min);
62  const auto f = (d * depth_units - depth_min) * scale;
63  const auto c = cm.get(f);
64 
65  dst->r = (uint8_t)c.x;
66  dst->g = (uint8_t)c.y;
67  dst->b = (uint8_t)c.z;
68  dst->a = 255;
69  }
70  else
71  {
72  dst->r = 0;
73  dst->g = 0;
74  dst->b = 0;
75  dst->a = 255;
76  }
77  dst++;
78  }
79 }
80 
81 void colorize_depth(depth_pixel* dst, const rs2::video_frame& depth, int colormap_id, float depth_min, float depth_max, float depth_units, bool equalize)
82 {
83  auto& cm = *colormap_presets[colormap_id];
84 
85  if (equalize) make_equalized_histogram(dst, depth, cm);
86  else make_value_cropped_frame(dst, depth, cm, depth_min, depth_max, depth_units);
87 }
88 
89 } // namespace
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:10806
GLint GLint GLsizei GLsizei GLsizei depth
GLenum GLenum dst
Definition: glext.h:1751
const void * get_data() const
Definition: rs_frame.hpp:545
unsigned short uint16_t
Definition: stdint.h:79
GLdouble GLdouble GLdouble w
d
Definition: rmse.py:171
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1960
unsigned char uint8_t
Definition: stdint.h:78
GLdouble f
void make_equalized_histogram(depth_pixel *dst, const rs2::video_frame &depth, const color_map &cm)
const GLubyte * c
Definition: glext.h:12690
#define SCOPED_PROFILER
Definition: Rs2Base.h:32
int get_height() const
Definition: rs_frame.hpp:671
int i
void colorize_depth(depth_pixel *dst, const rs2::video_frame &depth, int colormap_id, float depth_min, float depth_max, float depth_units, bool equalize)
void make_value_cropped_frame(depth_pixel *dst, const rs2::video_frame &depth, const color_map &cm, float depth_min, float depth_max, float depth_units)
int get_width() const
Definition: rs_frame.hpp:659


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