depth_noise_model.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Michael Pantic, ASL, ETH Zurich, Switzerland
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <algorithm>
17 #include <iostream>
18 
20 
21 inline bool DepthNoiseModel::InRange(const float depth) const {
22  return depth > this->min_depth && depth < this->max_depth;
23 }
24 
25 void D435DepthNoiseModel::ApplyNoise(const uint32_t width,
26  const uint32_t height, float *data) {
27  if (data == nullptr) {
28  return;
29  }
30 
31  float f = 0.5f * (width / tanf(h_fov / 2.0f));
32  float multiplier = (subpixel_err) / (f * baseline * 1e6f);
33  Eigen::Map<Eigen::VectorXf> data_vector_map(data, width * height);
34 
35  // Formula taken from the Intel Whitepaper:
36  // "Best-Known-Methods for Tuning Intel RealSenseā„¢ D400 Depth Cameras for Best Performance".
37  // We are using the theoretical RMS model formula.
38  Eigen::VectorXf rms_noise = (data_vector_map * 1000.0).array().square() * multiplier;
39  Eigen::VectorXf noise = rms_noise.array().square();
40 
41  // Sample noise for each pixel and transform variance according to error at this depth.
42  for (int i = 0; i < width * height; ++i) {
43  if (InRange(data_vector_map[i])) {
44  data_vector_map[i] +=
45  this->dist(this->gen) * std::min(((float)noise(i)), max_stdev);
46  } else {
47  data_vector_map[i] = this->bad_point;
48  }
49  }
50 }
51 
52 void KinectDepthNoiseModel::ApplyNoise(const uint32_t width,
53  const uint32_t height, float *data) {
54  if (data == nullptr) {
55  return;
56  }
57 
58  // Axial noise model from
59  // https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=6375037,
60  // Nguyen, Izadi & Lovell: "Modeling Kinect Sensor Noise for Improved 3D Reconstrucion and Tracking", 3DIM/3DPVT, 2012.
61  // We are using the 10-60 Degree model as an approximation.
62  Eigen::Map<Eigen::VectorXf> data_vector_map(data, width * height);
63  Eigen::VectorXf var_noise = 0.0012f + 0.0019f * (data_vector_map.array() - 0.4f).array().square();
64 
65  // Sample noise for each pixel and transform variance according to error at this depth.
66  for (int i = 0; i < width * height; ++i) {
67  if (InRange(data_vector_map[i])) {
68  data_vector_map[i] += this->dist(this->gen) * var_noise(i);
69  } else {
70  data_vector_map[i] = this->bad_point;
71  }
72  }
73 }
74 
75 
76 
77 void PMDDepthNoiseModel::ApplyNoise(const uint32_t width,
78  const uint32_t height, float *data) {
79  if (data == nullptr) {
80  return;
81  }
82 
83  // 1% error claimed by PMD
84  Eigen::Map<Eigen::VectorXf> data_vector_map(data, width * height);
85  Eigen::VectorXf var_noise = data_vector_map.array() * 0.01;
86 
87  // Sample noise for each pixel and transform variance according to error at this depth.
88  for (int i = 0; i < width * height; ++i) {
89  if (InRange(data_vector_map[i])) {
90  data_vector_map[i] += this->dist(this->gen) * var_noise(i);
91  } else {
92  data_vector_map[i] = this->bad_point;
93  }
94  }
95 }
uint8_t data[MAX_SIZE]
void ApplyNoise(uint32_t width, uint32_t height, float *data)
void ApplyNoise(uint32_t width, uint32_t height, float *data)
bool InRange(float depth) const
std::normal_distribution< float > dist
void ApplyNoise(uint32_t width, uint32_t height, float *data)


rotors_gazebo_plugins
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Mon Feb 28 2022 23:39:03