threshold.cpp
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 #include "../include/librealsense2/hpp/rs_sensor.hpp"
5 #include "../include/librealsense2/hpp/rs_processing.hpp"
6 
8 #include "context.h"
9 #include "environment.h"
10 #include "option.h"
11 #include "threshold.h"
12 #include "image.h"
13 
14 namespace librealsense
15 {
16  threshold::threshold() : stream_filter_processing_block("Threshold Filter"),_min(0.1f), _max(4.f)
17  {
20 
21  auto min_opt = std::make_shared<ptr_option<float>>(0.f, 16.f, 0.1f, 0.1f, &_min, "Min range in meters");
22 
23  auto max_opt = std::make_shared<ptr_option<float>>(0.f, 16.f, 0.1f, 4.f, &_max, "Max range in meters");
24 
26  std::make_shared<max_distance_option>(
27  max_opt,
28  min_opt));
29 
31  std::make_shared<min_distance_option>(
32  min_opt,
33  max_opt));
34  }
35 
37  {
38  if (!f.is<rs2::depth_frame>()) return f;
39 
41  {
44  }
45 
46  auto vf = f.as<rs2::depth_frame>();
47  auto width = vf.get_width();
48  auto height = vf.get_height();
49  auto new_f = source.allocate_video_frame(_target_stream_profile, f,
50  vf.get_bytes_per_pixel(), width, height, vf.get_stride_in_bytes(), RS2_EXTENSION_DEPTH_FRAME);
51 
52  if (new_f)
53  {
54  auto ptr = dynamic_cast<librealsense::depth_frame*>((librealsense::frame_interface*)new_f.get());
56 
57  auto depth_data = (uint16_t*)orig->get_frame_data();
58  auto new_data = (uint16_t*)ptr->get_frame_data();
59 
60  ptr->set_sensor(orig->get_sensor());
61  auto du = orig->get_units();
62 
63  memset(new_data, 0, width * height * sizeof(uint16_t));
64  for (int i = 0; i < width * height; i++)
65  {
66  auto dist = du * depth_data[i];
67  if (dist >= _min && dist <= _max) new_data[i] = depth_data[i];
68  }
69 
70  return new_f;
71  }
72 
73  return f;
74  }
75 }
orig
Definition: rmse.py:46
rs2_frame * get() const
Definition: rs_frame.hpp:590
stream_profile get_profile() const
Definition: rs_frame.hpp:557
rs2::stream_profile _source_stream_profile
Definition: threshold.h:25
unsigned short uint16_t
Definition: stdint.h:79
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
Definition: threshold.cpp:36
void register_option(rs2_option id, std::shared_ptr< option > option)
Definition: options.h:86
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
GLint GLsizei GLsizei height
const rs2_stream_profile * get() const
Definition: rs_frame.hpp:137
GLsizei GLsizei GLchar * source
int i
rs2::stream_profile _target_stream_profile
Definition: threshold.h:24
stream_profile clone(rs2_stream type, int index, rs2_format format) const
Definition: rs_frame.hpp:63
int get_width() const
Definition: rs_frame.hpp:659
GLint GLsizei width
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:11