hdr-merge.h
Go to the documentation of this file.
1 /* License: Apache 2.0. See LICENSE file in root directory.
2 Copyright(c) 2020 Intel Corporation. All Rights Reserved. */
3 
4 
5 #pragma once
6 
7 #include "synthetic-stream.h"
8 #include "option.h"
9 
10 namespace librealsense
11 {
13  {
14  public:
15  hdr_merge();
16 
17  protected:
18  bool should_process(const rs2::frame& frame) override;
20 
21 
22  private:
23  // for infrared 8 bit per pixel
24  const int IR_UNDER_SATURATED_VALUE_Y8 = 0x05; // 5
25  const int IR_OVER_SATURATED_VALUE_Y8 = 0xfa; // 250 (255 - IR_UNDER_SATURATED_VALUE_Y8)
26  // for infrared 10 bit per pixel
27  const int IR_UNDER_SATURATED_VALUE_Y16 = 0x14; // 20 (4 * IR_UNDER_SATURATED_VALUE_Y8)
28  const int IR_OVER_SATURATED_VALUE_Y16 = 0x3eb; // 1003 (1023 - IR_UNDER_SATURATED_VALUE_Y16)
29 
31 
34 
35  bool check_frames_mergeability(const rs2::frameset first_fs, const rs2::frameset second_fs, bool& use_ir) const;
36  bool should_ir_be_used_for_merging(const rs2::depth_frame& first_depth, const rs2::video_frame& first_ir,
37  const rs2::depth_frame& second_depth, const rs2::video_frame& second_ir) const;
38  rs2::frame merging_algorithm(const rs2::frame_source& source, const rs2::frameset first_fs,
39  const rs2::frameset second_fs, const bool use_ir) const;
40  template <typename T>
41  bool is_infrared_valid(T ir_value, rs2_format ir_format) const;
42  template <typename T>
43  void merge_frames_using_ir(uint16_t* new_data, uint16_t* d0, uint16_t* d1,
44  const rs2::video_frame& first_ir, const rs2::video_frame& second_ir, int width_height_prod) const;
45  void merge_frames_using_only_depth(uint16_t* new_data, uint16_t* d0, uint16_t* d1, int width_height_prod) const;
46 
47  unsigned long long _previous_depth_frame_counter;
49  std::map<int, rs2::frameset> _framesets;
51  };
53 
54  template <typename T>
56  const rs2::video_frame& first_ir, const rs2::video_frame& second_ir, int width_height_prod) const
57  {
58  auto i0 = (T*)first_ir.get_data();
59  auto i1 = (T*)second_ir.get_data();
60 
61  auto format = first_ir.get_profile().format();
62 
63  for (int i = 0; i < width_height_prod; i++)
64  {
65  if (is_infrared_valid<T>(i0[i], format) && d0[i])
66  new_data[i] = d0[i];
67  else if (is_infrared_valid<T>(i1[i], format) && d1[i])
68  new_data[i] = d1[i];
69  else
70  new_data[i] = 0;
71  }
72  }
73 
74  template <typename T>
75  bool hdr_merge::is_infrared_valid(T ir_value, rs2_format ir_format) const
76  {
77  bool result = false;
78  if (ir_format == RS2_FORMAT_Y8)
79  result = (ir_value > IR_UNDER_SATURATED_VALUE_Y8) && (ir_value < IR_OVER_SATURATED_VALUE_Y8);
80  else if (ir_format == RS2_FORMAT_Y16)
81  result = (ir_value > IR_UNDER_SATURATED_VALUE_Y16) && (ir_value < IR_OVER_SATURATED_VALUE_Y16);
82  else
83  result = false;
84  return result;
85  }
86 }
GLint i1
unsigned long long _previous_depth_frame_counter
Definition: hdr-merge.h:47
stream_profile get_profile() const
Definition: rs_frame.hpp:557
const int NUMBER_OF_FRAMES_WITHOUT_METADATA_FOR_WARNING
Definition: hdr-merge.h:30
const void * get_data() const
Definition: rs_frame.hpp:545
unsigned short uint16_t
Definition: stdint.h:79
rs2::frame merging_algorithm(const rs2::frame_source &source, const rs2::frameset first_fs, const rs2::frameset second_fs, const bool use_ir) const
Definition: hdr-merge.cpp:170
GLdouble f
bool is_infrared_valid(T ir_value, rs2_format ir_format) const
Definition: hdr-merge.h:75
const int IR_UNDER_SATURATED_VALUE_Y16
Definition: hdr-merge.h:27
bool should_ir_be_used_for_merging(const rs2::depth_frame &first_depth, const rs2::video_frame &first_ir, const rs2::depth_frame &second_depth, const rs2::video_frame &second_ir) const
Definition: hdr-merge.cpp:241
rs2::frame _depth_merged_frame
Definition: hdr-merge.h:50
GLint GLint GLsizei GLint GLenum format
void merge_frames_using_ir(uint16_t *new_data, uint16_t *d0, uint16_t *d1, const rs2::video_frame &first_ir, const rs2::video_frame &second_ir, int width_height_prod) const
Definition: hdr-merge.h:55
std::map< int, rs2::frameset > _framesets
Definition: hdr-merge.h:49
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
bool check_frames_mergeability(const rs2::frameset first_fs, const rs2::frameset second_fs, bool &use_ir) const
Definition: hdr-merge.cpp:145
int _frames_without_requested_metadata_counter
Definition: hdr-merge.h:48
rs2_format format() const
Definition: rs_frame.hpp:44
const int IR_UNDER_SATURATED_VALUE_Y8
Definition: hdr-merge.h:24
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
Definition: hdr-merge.cpp:62
void reset_warning_counter_on_pipe_restart(const rs2::depth_frame &depth_frame)
Definition: hdr-merge.cpp:51
GLsizei GLsizei GLchar * source
int i
const int IR_OVER_SATURATED_VALUE_Y16
Definition: hdr-merge.h:28
void merge_frames_using_only_depth(uint16_t *new_data, uint16_t *d0, uint16_t *d1, int width_height_prod) const
Definition: hdr-merge.cpp:228
void discard_depth_merged_frame_if_needed(const rs2::frame &f)
Definition: hdr-merge.cpp:121
GLuint64EXT * result
Definition: glext.h:10921
bool should_process(const rs2::frame &frame) override
Definition: hdr-merge.cpp:15
MAP_EXTENSION(RS2_EXTENSION_POINTS, librealsense::points)
const int IR_OVER_SATURATED_VALUE_Y8
Definition: hdr-merge.h:25


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