test_speckle_filter.cpp
Go to the documentation of this file.
00001 
00059 /*
00060  * amp_conf_filter_test.cpp
00061  *
00062  *  Created on: Apr 18, 2011
00063  *      Author: goa-wq
00064  */
00065 
00066 //AmplitudeFilter
00067 #include <cob_3d_mapping_filters/speckle_filter.h>
00068 //#include <cob_3d_mapping_filters/impl/speckle_filter.hpp>
00069 
00070 #include <pcl/point_types.h>
00071 #include <pcl/io/pcd_io.h>
00072 #include <cob_3d_mapping_common/point_types.h>
00073 //#include <sensor_msgs/point_cloud_conversion.h>
00074 
00075 #include <boost/timer.hpp>
00076 #include "cob_3d_mapping_common/stop_watch.h"
00077 #include <iostream>
00078 #include <fstream>
00079 #include <boost/random.hpp>
00080 #include <boost/random/normal_distribution.hpp>
00081 
00082 /* Methods for testing filters */
00083 
00084 double
00085 TestProcessingTimeOnce (unsigned int cloud_size, unsigned int iterations)
00086 {
00087   cob_3d_mapping_filters::SpeckleFilter<PointXYZ> filter;
00088   pcl::PointCloud<PointXYZ>::Ptr cloud (new pcl::PointCloud<PointXYZ> ());
00089   pcl::PointCloud<PointXYZ>::Ptr cloud_out (new pcl::PointCloud<PointXYZ> ());
00090 
00091   cloud->points.resize (cloud_size);
00092   cloud->width = sqrt (cloud_size);
00093   cloud->height = sqrt (cloud_size);
00094   for (unsigned int i = 0; i < cloud_size; i++)
00095   {
00096     PointXYZ pt;
00097     pt.x = pt.y = pt.z = 1;
00098     cloud->points[i] = pt;
00099   }
00100   filter.setInputCloud (cloud);
00101   //boost::timer t;
00102   double time = 0;
00103   for (unsigned int i = 0; i < iterations; i++)
00104   {
00105     PrecisionStopWatch sw;
00106     sw.precisionStart ();
00107     filter.filter (*cloud_out);
00108     time += sw.precisionStop ();
00109   }
00110   time /= iterations;
00111   std::cout << "Cloud size " << cloud_size << ": " << time << " s" << std::endl;
00112   return time;
00113 }
00114 
00115 void
00116 TestProcessingTime ()
00117 {
00118   std::ofstream file;
00119   file.open ("/home/goa/tmp/speckle_filter_timing.dat");
00120   file << "#No. of points\ttime (s)\n";
00121   for (unsigned int cloud_size = 40000; cloud_size <= 400000; cloud_size += 40000)
00122   {
00123     double time = TestProcessingTimeOnce (cloud_size, 1000);
00124     file << cloud_size << "\t" << time << "\n";
00125   }
00126   file.close ();
00127 
00128 }
00129 
00130 void
00131 DoSampleRun ()
00132 {
00133   cob_3d_mapping_filters::SpeckleFilter<PointXYZ> filter;
00134   pcl::PointCloud<PointXYZ>::Ptr cloud (new pcl::PointCloud<PointXYZ> ());
00135   pcl::PointCloud<PointXYZ>::Ptr cloud_out (new pcl::PointCloud<PointXYZ> ());
00136   pcl::io::loadPCDFile ("/home/goa/Ubuntu One/diss/images/raw/filter_sequence_amplitude2.pcd", *cloud);
00137   filter.setInputCloud (cloud);
00138   filter.filter (*cloud_out);
00139   pcl::io::savePCDFileASCII ("/home/goa/Ubuntu One/diss/images/raw/filter_sequence_speckle2.pcd", *cloud_out);
00140 }
00141 
00142 void
00143 DoSampleRun2 ()
00144 {
00145   cob_3d_mapping_filters::SpeckleFilter<PointXYZ> filter;
00146   pcl::PointCloud<PointXYZ>::Ptr cloud (new pcl::PointCloud<PointXYZ> ());
00147   pcl::PointCloud<PointXYZ>::Ptr cloud_out (new pcl::PointCloud<PointXYZ> ());
00148   cloud->width = 640;
00149   cloud->height = 480;
00150   double x = 0, y = 0;
00151   for (unsigned int i = 0; i < cloud->width; i++, y += 0.001)
00152   {
00153     x = 0;
00154     for (unsigned int j = 0; j < cloud->height; j++, x += 0.001)
00155     {
00156       PointXYZ pt;
00157       pt.x = x;
00158       pt.y = y;
00159       pt.z = 1;
00160       cloud->points.push_back (pt);
00161     }
00162   }
00163   boost::mt19937 rng; // I don't seed it on purpouse (it's not relevant)
00164   boost::normal_distribution<> nd (0.0, 0.05);
00165   boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > var_nor (rng, nd);
00166 
00167   for (unsigned int i = 0; i < 3000; i++)
00168     cloud->points[i * 100].z += var_nor ();
00169 
00170   //pcl::io::savePCDFileASCII("/tmp/spk_cloud.pcd", *cloud);
00171   filter.setInputCloud (cloud);
00172   for (unsigned int s = 10; s <= 100; s += 10)
00173   {
00174     std::stringstream ss;
00175     ss << "/tmp/spk_acc_" << s << ".txt";
00176     std::ofstream file;
00177     file.open (ss.str ().c_str ());
00178     file << "thr\ttp\tfn\tfp\n";
00179     for (double c = 0.01; c <= 0.1; c += 0.01)
00180     {
00181       filter.setFilterParam (s, c);
00182       filter.filter (*cloud_out);
00183       pcl::PointIndices::Ptr ind = filter.getRemovedIndices ();
00184       std::cout << "Cloud size " << cloud_out->size () << ", ind: " << ind->indices.size () << std::endl;
00185       int fn_ctr = 0, tp_ctr = 0;
00186       for (unsigned int i = 0; i < 3000; i++)
00187       {
00188         bool found = false;
00189         for (unsigned int j = 0; j < ind->indices.size (); j++)
00190         {
00191           if (ind->indices[j] == i * 100)
00192           {
00193             tp_ctr++;
00194             found = true;
00195             break;
00196           }
00197         }
00198         if (!found)
00199           fn_ctr++;
00200       }
00201       int fp_ctr = ind->indices.size () - tp_ctr;
00202       double fn_ratio = (double)fn_ctr / 3000;
00203       double fp_ratio = (double)fp_ctr / 3000;
00204       double tp_ratio = (double)tp_ctr / 3000;
00205       file << c << "\t" << tp_ratio << "\t" << fn_ratio << "\t" << fp_ratio << "\n";
00206       std::cout << "c: " << c << " fn: " << fn_ratio << ", tp: " << tp_ratio << " fp: " << fp_ratio << std::endl;
00207     }
00208     file.close ();
00209   }
00210 }
00211 
00212 int
00213 main ()
00214 {
00215   DoSampleRun2 ();
00216   //TestProcessingTimeOnce(10000, 1);
00217 }
00218 


cob_3d_mapping_filters
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:02:54