-
Notifications
You must be signed in to change notification settings - Fork 29
Noise model #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Noise model #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef NOISE_MODEL_H | ||
#define NOISE_MODEL_H | ||
|
||
#include <math.h> | ||
#include <vector> | ||
#include <iostream> | ||
#include <iomanip> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
#include <string> | ||
#include <map> | ||
#include <random> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include files that aren't used directly in the header itself should go in the .cpp file. This keeps your interfaces cleaner and helps with build times on large projects. In this case all the includes but |
||
|
||
namespace gl_depth_sim | ||
{ | ||
std::vector<float> noise(std::vector<float> distance); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I know what you're trying to do here, others will not. Instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing and returning very large objects (like these vectors) can be very expensive. Consider passing the input as a constant reference: There's arguments to be made that returning by value is not so bad, but you do have options:
void noise(const std::vector<float>& distance_in, std::vector<float>& distance_out);
void (std::vector<float>& distance); |
||
|
||
} | ||
#endif // NOISE_MODEL_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#include "gl_depth_sim/sim_depth_camera.h" | ||
#include "gl_depth_sim/mesh_loader.h" | ||
#include "gl_depth_sim/interfaces/pcl_interface.h" | ||
|
||
#include "gl_depth_sim/interfaces/noise_model.h" | ||
#include <pcl_ros/point_cloud.h> | ||
#include <pcl_conversions/pcl_conversions.h> | ||
#include <ros/ros.h> | ||
|
@@ -97,7 +97,9 @@ int main(int argc, char** argv) | |
|
||
const auto pose = lookat(camera_pos, look_at, Eigen::Vector3d(0,0,1)); | ||
|
||
const auto depth_img = sim.render(pose); | ||
auto depth_img = sim.render(pose); | ||
|
||
depth_img.data = gl_depth_sim::noise(depth_img.data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a ROS parameter that optionally applies the noise. This should be something that people opt into. |
||
|
||
frame_counter++; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "gl_depth_sim/interfaces/noise_model.h" | ||
|
||
std::vector<float> gl_depth_sim::noise(std::vector<float> distance) | ||
{ | ||
float segma; | ||
std::random_device r; | ||
std::seed_seq seed2{r(), r(), r(), r(), r(), r(), r(), r()}; | ||
std::mt19937 e2(seed2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A thought: Re-creating these every function call is probably quite expensive. You might consider moving the Don't worry about it for now, but if you don't understand the idea of random number seeds then please look it up. |
||
|
||
for (int i = 0 ; i < distance.size() ;++i){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sign/unsigned comparison.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively you can re-write the entire loop using C++11 for (float& r : distance)
{
// ...
r = normal_dist(e2);
} |
||
// Seed with a real random value, if available | ||
segma= 0.0012+0.0019* pow(distance[i]-0.4,2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these numbers, or |
||
float r = distance[i]; | ||
// Generate a normal distribution around that mean | ||
std::normal_distribution<> normal_dist(r, segma); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise this line creates a normal distribution that is of type double. The |
||
distance[i] = normal_dist(e2); | ||
} | ||
return distance; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer the C++ equivalent header
<cmath>
over the C includemath.h
.They define the same things but the cmath includes functions in the
std::
namespace.