Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #include <ros/ros.h>
00062 #include <pcl_conversions/pcl_conversions.h>
00063
00064
00065 #include <std_msgs/String.h>
00066 #include <sensor_msgs/PointCloud2.h>
00067
00068
00069
00070
00071
00072
00073 #include <boost/random/normal_distribution.hpp>
00074 #include <boost/random.hpp>
00075
00076 #include <pcl/point_cloud.h>
00077 #include <pcl/point_types.h>
00078 #include <pcl/conversions.h>
00079
00080
00081 class noise_gen
00082 {
00083
00084 public:
00085
00086 ros::NodeHandle n;
00087
00088
00089 ros::Publisher pub_;
00090
00091
00092 ros::Subscriber sub_;
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 noise_gen()
00110 {
00111
00112 std::string in_topic,out_topic;
00113 in_topic = "cloud_in";
00114 out_topic = "cloud_out";
00115
00116
00117 pub_ = n.advertise<sensor_msgs::PointCloud2>(out_topic, 1);
00118 sub_ = n.subscribe(in_topic, 1, &noise_gen::cloud_callback, this);
00119 }
00120
00121
00122 ~noise_gen()
00123 {
00124 }
00125
00126 double random_number_kinect(double z)
00127 {
00128
00129
00130 double mean = 0.0;
00131
00132 float sigma;
00133
00134
00135
00136 sigma= ((5*z*z)/100000);
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 typedef boost::normal_distribution<double> NormalDistribution;
00147 typedef boost::mt19937 RandomGenerator;
00148 typedef boost::variate_generator<RandomGenerator&,NormalDistribution> GaussianGenerator;
00150 static RandomGenerator rng(static_cast<unsigned> (time(0)));
00151
00152
00153 NormalDistribution gaussian_dist(mean, sigma);
00154
00155
00156
00157
00158
00159 GaussianGenerator generator(rng, gaussian_dist);
00160 return generator();
00161 }
00162
00163 double random_number_static(double sigma)
00164 {
00165
00166
00167 double mean = 0.0;
00168
00169
00170
00171
00172
00173
00174 typedef boost::normal_distribution<double> NormalDistribution;
00175 typedef boost::mt19937 RandomGenerator;
00176 typedef boost::variate_generator<RandomGenerator&,NormalDistribution> GaussianGenerator;
00178 static RandomGenerator rng(static_cast<unsigned> (time(0)));
00179
00180
00181 NormalDistribution gaussian_dist(mean, sigma);
00182
00183
00184
00185
00186
00187 GaussianGenerator generator(rng, gaussian_dist);
00188 return generator();
00189 }
00190
00191
00192
00193 void cloud_callback(const sensor_msgs::PointCloud2 cloud_in)
00194 {
00195
00196
00197
00198
00199 bool bin_mode = true;
00200 double sigma = 0.002;
00201
00202
00203 sensor_msgs::PointCloud2 out_msg;
00204 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_work (new pcl::PointCloud<pcl::PointXYZRGB>);
00205
00206 pcl::PCLPointCloud2 cloud_work2;
00207 pcl_conversions::toPCL(out_msg, cloud_work2);
00208 pcl::fromPCLPointCloud2(cloud_work2, *cloud_work);
00209
00210
00211
00212 for (size_t i = 0; i < cloud_work->points.size(); ++i) {
00213
00214
00215
00216 if ( isnan( cloud_work->points[i].z)==true)
00217 {
00218 continue;
00219 }
00220 else
00221 {
00222 if(bin_mode==true)
00223 {
00224
00225 double z_float= cloud_work->points[i].z+random_number_static(sigma);
00226
00227
00228 double z_bin =round(1090-(348/z_float));
00229
00230 cloud_work->points[i].z = (-348/(z_bin-1090));
00231 }
00232 else
00233 cloud_work->points[i].z += random_number_static(sigma);
00234 }
00235
00236 }
00237 pcl::toPCLPointCloud2(*cloud_work, cloud_work2);
00238 pcl_conversions::fromPCL(cloud_work2, out_msg);
00239
00240
00241 pub_.publish(out_msg);
00242
00243 }
00244
00245
00246 };
00247
00248
00249
00250
00251
00252 int main (int argc, char** argv)
00253 {
00254 ros::init (argc, argv, "eval_node");
00255 noise_gen nodeClass;
00256
00257 while(nodeClass.n.ok())
00258 {
00259
00260 ros::spinOnce();
00261 }
00262
00263
00264
00265 return 0;
00266 }
00267
00268