其他分享
首页 > 其他分享> > librealsense filter class hierachy

librealsense filter class hierachy

作者:互联网

1. rs2::decimation_filter

https://intelrealsense.github.io/librealsense/doxygen/classrs2_1_1decimation__filter.html

https://intelrealsense.github.io/librealsense/doxygen/rs__processing_8hpp_source.html

 1      class decimation_filter : public filter
 2      {
 3      public:
 4          decimation_filter() : filter(init(), 1) {}
 5          decimation_filter(float magnitude) : filter(init(), 1)
 6          {
 7              set_option(RS2_OPTION_FILTER_MAGNITUDE, magnitude);
 8          }
 9  
10          decimation_filter(filter f) : filter(f)
11          {
12               rs2_error* e = nullptr;
13               if (!rs2_is_processing_block_extendable_to(f.get(), RS2_EXTENSION_DECIMATION_FILTER, &e) && !e)
14               {
15                   _block.reset();
16               }
17               error::handle(e);
18          }
19  
20      private:
21          friend class context;
22  
23          std::shared_ptr<rs2_processing_block> init()
24          {
25              rs2_error* e = nullptr;
26              auto block = std::shared_ptr<rs2_processing_block>(
27                  rs2_create_decimation_filter_block(&e),
28                  rs2_delete_processing_block);
29              error::handle(e);
30  
31              // Redirect options API to the processing block
32              //options::operator=(this);
33  
34              return block;
35          }
36      };

 

2. rs2_create_decimation_filter_block: rs_processing.h, src/rs.cpp

1 // src/rs.cpp
2 rs2_processing_block* rs2_create_decimation_filter_block(rs2_error** error) BEGIN_API_CALL
3 {
4     auto block = std::make_shared<librealsense::decimation_filter>();
5 
6     return new rs2_processing_block{ block };
7 }
8 NOARGS_HANDLE_EXCEPTIONS_AND_RETURN(nullptr)

 

3. librealsense::decimation_filter: src/proc/decimation-filter.h, src/proc/decimation-filter.cpp

 1 namespace librealsense
 2 {
 3 
 4     class decimation_filter : public stream_filter_processing_block
 5     {
 6     public:
 7         decimation_filter();
 8 
 9     protected:
10         rs2::frame prepare_target_frame(const rs2::frame& f, const rs2::frame_source& source, rs2_extension tgt_type);
11 
12         void decimate_depth(const uint16_t * frame_data_in, uint16_t * frame_data_out,
13             size_t width_in, size_t height_in, size_t scale);
14 
15         void decimate_others(rs2_format format, const void * frame_data_in, void * frame_data_out,
16             size_t width_in, size_t height_in, size_t scale);
17         rs2::frame process_frame(const rs2::frame_source& source, const rs2::frame& f) override;
18 
19     private:
20         void    update_output_profile(const rs2::frame& f);
21 
22         uint8_t                 _decimation_factor;
23         uint8_t                 _control_val;
24         uint8_t                 _patch_size;
25         uint8_t                 _kernel_size;
26         rs2::stream_profile     _source_stream_profile;
27         rs2::stream_profile     _target_stream_profile;
28         std::map<std::tuple<const rs2_stream_profile*, uint8_t>, rs2::stream_profile> _registered_profiles;
29         uint16_t                _real_width;        // Number of rows/columns with real datain the decimated image
30         uint16_t                _real_height;       // Correspond to w,h in the reference code
31         uint16_t                _padded_width;      // Corresponds to w4/h4 in the reference code
32         uint16_t                _padded_height;
33         bool                    _recalc_profile;
34         bool                    _options_changed;   // Tracking changes imposed by user
35     };
36     MAP_EXTENSION(RS2_EXTENSION_DECIMATION_FILTER, librealsense::decimation_filter);
37 }

 

 1     rs2::frame decimation_filter::process_frame(const rs2::frame_source& source, const rs2::frame& f)
 2     {
 3         update_output_profile(f);
 4 
 5         auto src = f.as<rs2::video_frame>();
 6         rs2::stream_profile profile = f.get_profile();
 7         rs2_format format = profile.format();
 8         rs2_stream type = profile.stream_type();
 9 
10         rs2_extension tgt_type;
11         if (type == RS2_STREAM_COLOR || type == RS2_STREAM_INFRARED)
12             tgt_type = RS2_EXTENSION_VIDEO_FRAME;
13         else
14             tgt_type = f.is<rs2::disparity_frame>() ? RS2_EXTENSION_DISPARITY_FRAME : RS2_EXTENSION_DEPTH_FRAME;
15 
16         if (auto tgt = prepare_target_frame(f, source, tgt_type))
17         {
18             if (format == RS2_FORMAT_Z16)
19             {
20                 decimate_depth(static_cast<const uint16_t*>(src.get_data()),
21                     static_cast<uint16_t*>(const_cast<void*>(tgt.get_data())),
22                     src.get_width(), src.get_height(), this->_patch_size);
23             }
24             else
25             {
26                 decimate_others(format, src.get_data(),
27                     const_cast<void*>(tgt.get_data()),
28                     src.get_width(), src.get_height(), this->_patch_size);
29             }
30             return tgt;
31         }
32         return f;
33     }

 

标签:profile,librealsense,decimation,frame,filter,block,class,rs2
来源: https://www.cnblogs.com/imoon22/p/14276867.html