post-processing-filter.h
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 #pragma once
5 
6 #include <librealsense2/rs.hpp>
7 #include <librealsense2/rsutil.h> // for projection utilities
8 #include <model-views.h>
9 #include <viewer.h>
10 
11 
12 /*
13  Generic base class for any custom post-processing filter that is added after all
14  the usual supported filters.
15 
16  A worker thread does the main job in the background, once start() is called.
17  See object_detection_filters.
18 */
20 {
23 
24 protected:
25  // Default ctor to use with post_processing_filters_list::register_filter() cannot take
26  // anything but a name. This name is what the user will see in the list of post-processors.
28  : rs2::filter( [&]( rs2::frame f, rs2::frame_source & source ) {
29  // Process the frame, take the result and post it for the next post-processor
30  source.frame_ready(process_frame(f));
31  } )
32  , _name( name )
33  , _pb_enabled( true )
34  {
35  }
36 
37  bool is_pb_enabled() const { return _pb_enabled; }
38 
39 public:
40  // Called from post_processing_filter_model when this particular processing block
41  // is enabled or disabled
42  virtual void on_processing_block_enable( bool e )
43  {
44  _pb_enabled = e;
45  }
46 
47  // Returns the name of the filter
48  std::string const & get_name() const { return _name; }
49 
50  virtual void start( rs2::subdevice_model & model )
51  {
52  LOG_INFO("Starting " + get_name());
53  }
54 
55 protected:
56  // Main handler for each frameset we get
57  virtual rs2::frame process_frame( rs2::frame fs ) = 0;
58 
59 
60  // Helper fn to get the frame context when logs are written, e.g.:
61  // LOG(ERROR) << get_context(fs) << "just a dummy error";
63  {
64  std::ostringstream ss;
65  if( f )
66  ss << "[#" << f.get_frame_number() << "] ";
67  return ss.str();
68  }
69 
70 
71  // Returns the intrinsics and extrinsics for a depth and color frame.
74  rs2_intrinsics & color_intrin, rs2_intrinsics & depth_intrin,
75  rs2_extrinsics & color_extrin, rs2_extrinsics & depth_extrin )
76  {
78  color_intrin = color_profile.get_intrinsics();
79  if( df )
80  {
82  depth_intrin = depth_profile.get_intrinsics();
83  depth_extrin = depth_profile.get_extrinsics_to( color_profile );
84  color_extrin = color_profile.get_extrinsics_to( depth_profile );
85  }
86  }
87 
88 
89  // Returns a bounding box, input in the color-frame coordinates, after converting it to the corresponding
90  // coordinates in the depth frame.
92  rs2::rect const & bbox, rs2::depth_frame df,
93  rs2_intrinsics const & color_intrin, rs2_intrinsics const & depth_intrin,
94  rs2_extrinsics const & color_extrin, rs2_extrinsics const & depth_extrin )
95  {
96  // NOTE: this is a bit expensive as it actually searches along a projected beam from 0.1m to 10 meter
97  float top_left_depth[2], top_left_color[2] = { bbox.x, bbox.y };
98  float bottom_right_depth[2], bottom_right_color[2] = { bbox.x + bbox.w, bbox.y + bbox.h };
100  reinterpret_cast<const uint16_t *>(df.get_data()), df.get_units(), 0.1f, 10,
101  &depth_intrin, &color_intrin,
102  &color_extrin, &depth_extrin,
103  top_left_color );
104  rs2_project_color_pixel_to_depth_pixel( bottom_right_depth,
105  reinterpret_cast<const uint16_t *>(df.get_data()), df.get_units(), 0.1f, 10,
106  &depth_intrin, &color_intrin,
107  &color_extrin, &depth_extrin,
108  bottom_right_color );
109  float left = top_left_depth[0];
110  float top = top_left_depth[1];
111  float right = bottom_right_depth[0];
112  float bottom = bottom_right_depth[1];
113  return rs2::rect { left, top, right - left, bottom - top };
114  }
115 };
float y
Definition: rendering.h:499
rs2::rect project_rect_to_depth(rs2::rect const &bbox, rs2::depth_frame df, rs2_intrinsics const &color_intrin, rs2_intrinsics const &depth_intrin, rs2_extrinsics const &color_extrin, rs2_extrinsics const &depth_extrin)
GLuint const GLchar * name
GLdouble GLdouble GLdouble top
rs2_extrinsics get_extrinsics_to(const stream_profile &to) const
Definition: rs_frame.hpp:148
stream_profile get_profile() const
Definition: rs_frame.hpp:557
float get_units() const
Definition: rs_frame.hpp:845
const void * get_data() const
Definition: rs_frame.hpp:545
Definition: cah-model.h:10
GLsizei const GLchar *const * string
e
Definition: rmse.py:177
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
post_processing_filter(std::string const &name)
virtual rs2::frame process_frame(rs2::frame fs)=0
float x
Definition: rendering.h:499
GLdouble f
float h
Definition: rendering.h:500
virtual void on_processing_block_enable(bool e)
GLint left
Definition: glext.h:1963
void get_trinsics(rs2::video_frame cf, rs2::depth_frame df, rs2_intrinsics &color_intrin, rs2_intrinsics &depth_intrin, rs2_extrinsics &color_extrin, rs2_extrinsics &depth_extrin)
rs2_intrinsics get_intrinsics() const
Definition: rs_frame.hpp:238
float w
Definition: rendering.h:500
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
LOG_INFO("Log message using LOG_INFO()")
GLdouble right
Video stream intrinsics.
Definition: rs_types.h:58
GLsizei GLsizei GLchar * source
virtual void start(rs2::subdevice_model &model)
static void rs2_project_color_pixel_to_depth_pixel(float to_pixel[2], const uint16_t *data, float depth_scale, float depth_min, float depth_max, const struct rs2_intrinsics *depth_intrin, const struct rs2_intrinsics *color_intrin, const struct rs2_extrinsics *color_to_depth, const struct rs2_extrinsics *depth_to_color, const float from_pixel[2])
Definition: rsutil.h:212
std::string get_context(rs2::frame f=rs2::frame()) const
std::string const & get_name() const
GLdouble GLdouble bottom


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