units-transform.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #include "../include/librealsense2/hpp/rs_sensor.hpp"
5 #include "../include/librealsense2/hpp/rs_processing.hpp"
6 
8 #include "environment.h"
9 #include "units-transform.h"
10 
11 namespace librealsense
12 {
14  {
17  }
18 
20  {
22  {
25 
26  if (!_depth_units)
27  {
28  try
29  {
30  auto sensor = ((frame_interface*)f.get())->get_sensor().get();
31  _depth_units = sensor->get_option(RS2_OPTION_DEPTH_UNITS).query();
32  }
33  catch (...)
34  {
35  // reset stream profile in case of failure.
38  LOG_ERROR("Failed obtaining depth units option");
39  }
40  }
41 
42  auto vf = f.as<rs2::depth_frame>();
43  _width = vf.get_width();
44  _height = vf.get_height();
45  _stride = sizeof(float) * _width;
46  _bpp = sizeof(float);
47  }
48  }
49 
51  {
53 
54  auto new_f = source.allocate_video_frame( _target_stream_profile,
55  f,
56  (int)_bpp,
57  (int)_width,
58  (int)_height,
59  (int)_stride,
61 
62  if (new_f && _depth_units)
63  {
64  auto ptr = dynamic_cast<librealsense::depth_frame*>((librealsense::frame_interface*)new_f.get());
66 
67  auto depth_data = (uint16_t*)orig->get_frame_data();
68  auto new_data = (float*)ptr->get_frame_data();
69 
70  ptr->set_sensor(orig->get_sensor());
71 
72  memset(new_data, 0, _width * _height * sizeof(float));
73  for (int i = 0; i < _width * _height; i++)
74  {
75  float dist = *_depth_units * depth_data[i];
76  new_data[i] = dist;
77  }
78 
79  return new_f;
80  }
81 
82  return f;
83  }
84 
86  {
87  if (!frame.is<rs2::depth_frame>()) return false;
88  return true;
89  }
90 }
orig
Definition: rmse.py:46
rs2_frame * get() const
Definition: rs_frame.hpp:590
stream_profile get_profile() const
Definition: rs_frame.hpp:557
unsigned short uint16_t
Definition: stdint.h:79
frame allocate_video_frame(const stream_profile &profile, const frame &original, int new_bpp=0, int new_width=0, int new_height=0, int new_stride=0, rs2_extension frame_type=RS2_EXTENSION_VIDEO_FRAME) const
GLdouble f
bool is() const
Definition: rs_frame.hpp:570
bool should_process(const rs2::frame &frame) override
#define LOG_ERROR(...)
Definition: src/types.h:242
rs2::stream_profile _source_stream_profile
const rs2_stream_profile * get() const
Definition: rs_frame.hpp:137
GLsizei GLsizei GLchar * source
void update_configuration(const rs2::frame &f)
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
int i
optional_value< float > _depth_units
stream_profile clone(rs2_stream type, int index, rs2_format format) const
Definition: rs_frame.hpp:63
rs2::stream_profile _target_stream_profile
T as() const
Definition: rs_frame.hpp:580


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