test_surface_class_estimation.cpp
Go to the documentation of this file.
00001 
00063 // OpenCV:
00064 #include <opencv2/core/core.hpp>
00065 #include <cv.h>
00066 #include <highgui.h>
00067 
00068 // Boost:
00069 #include <boost/program_options.hpp>
00070 #include <boost/timer.hpp>
00071 
00072 // PCL:
00073 #include <pcl/point_types.h>
00074 #include <pcl/io/pcd_io.h>
00075 #include <pcl/visualization/pcl_visualizer.h>
00076 #include <pcl/visualization/point_cloud_handlers.h>
00077 /*#include <pcl/features/normal_3d.h>
00078 #include <pcl/features/normal_3d_omp.h>
00079 #include <pcl/features/integral_image_normal.h>*/
00080 
00081 // Package Includes:
00082 #include "cob_3d_mapping_common/point_types.h"
00083 #include "cob_3d_mapping_common/stop_watch.h"
00084 #include "cob_3d_mapping_common/label_defines.h"
00085 #include "cob_3d_features/fast_edge_estimation_3d.h"
00086 #include "cob_3d_features/organized_normal_estimation.h"
00087 #include "cob_3d_features/organized_curvature_estimation.h"
00088 #include "cob_3d_features/curvature_classifier.h"
00089 #include "cob_3d_features/impl/curvature_classifier.hpp"
00090 //#include "cob_3d_mapping_features/segmentation.h"
00091 
00092 
00093 using namespace std;
00094 using namespace pcl;
00095 
00096 typedef visualization::PointCloudColorHandlerRGBField<PointXYZRGB> ColorHdlRGB;
00097 
00098 string file_;
00099 float cmax_;
00100 int radius_;
00101 int circle_;
00102 float th_;
00103 int threads_;
00104 int rfp_;
00105 float lower_, upper_;
00106 
00107 void readOptions(int argc, char* argv[])
00108 {
00109   using namespace boost::program_options;
00110   options_description options("Options");
00111   options.add_options()
00112     ("help", "produce help message")
00113     ("in,i", value<string>(&file_), "input pcd file")
00114     ("cmax,t", value<float>(&cmax_)->default_value(0.5), "max curvature")
00115     ("threshold_modifier,m", value<float>(&th_)->default_value(4.0), "thresholdmodifier")
00116     ("radius,r", value<int>(&radius_)->default_value(5), "radius")
00117     ("circle,c", value<int>(&circle_)->default_value(2),"circle steps")
00118     ("feature,f", value<int>(&rfp_)->default_value(20), "set 3d edge estimation radius")
00119     ("lower,l", value<float>(&lower_)->default_value(1.5), "lower curvature threshold")
00120     ("upper,u", value<float>(&upper_)->default_value(6.0), "upper curvature threshold")
00121     ;
00122 
00123   positional_options_description p_opt;
00124   p_opt.add("in", 1);
00125   variables_map vm;
00126   store(command_line_parser(argc, argv).options(options).positional(p_opt).run(), vm);
00127   notify(vm);
00128 
00129   if (vm.count("help"))
00130   {
00131     cout << options << endl;
00132     exit(0);
00133   }
00134 }
00135 
00136 void applyColor(int i, PointCloud<PointLabel>::Ptr p, PointCloud<PointXYZRGB>::Ptr col)
00137 {
00138   switch (p->points[i].label)
00139   {
00140   case I_SPHERE: //sphere
00141     col->points[i].r = 255;
00142     col->points[i].g = 0;
00143     col->points[i].b = 255;
00144     break;
00145   case I_CYL: //cylinder
00146     col->points[i].r = 255;
00147     col->points[i].g = 255;
00148     col->points[i].b = 0;
00149     break;
00150   case I_PLANE: //plane
00151     col->points[i].r = 0;
00152     col->points[i].g = 0;
00153     col->points[i].b = 255;
00154     break;
00155   case I_EDGE: //edge
00156     col->points[i].r = 0;
00157     col->points[i].g = 255;
00158     col->points[i].b = 0;
00159     break;
00160   case I_BORDER: //border
00161     col->points[i].r = 255;
00162     col->points[i].g = 0;
00163     col->points[i].b = 0;
00164     break;
00165   default:
00166     col->points[i].r = 100;
00167     col->points[i].g = 100;
00168     col->points[i].b = 100;
00169     break;
00170   }
00171 }
00172 
00173 
00174 int main(int argc, char** argv)
00175 {
00176   readOptions(argc, argv);
00177   //boost::timer t;
00178   PrecisionStopWatch t;
00179 
00180   PointCloud<PointXYZRGB>::Ptr p(new PointCloud<PointXYZRGB>);
00181   PointCloud<PointXYZRGB>::Ptr p2(new PointCloud<PointXYZRGB>);
00182   PointCloud<PointLabel>::Ptr l(new PointCloud<PointLabel>);
00183   PointCloud<PointLabel>::Ptr le(new PointCloud<PointLabel>);
00184   PointCloud<Normal>::Ptr n(new PointCloud<Normal>);
00185   PointCloud<PrincipalCurvatures>::Ptr pc(new PointCloud<PrincipalCurvatures>);
00186   PointCloud<InterestPoint>::Ptr ip3d(new PointCloud<InterestPoint>);
00187 
00188   PCDReader r;
00189   if (r.read(file_, *p) == -1) return(0);
00190   *p2 = *p;
00191 
00192 /*
00193   t.precisionStart();
00194   IntegralImageNormalEstimation<PointXYZRGB,Normal> ne;
00195   ne.setNormalEstimationMethod (ne.COVARIANCE_MATRIX);
00196   ne.setMaxDepthChangeFactor(0.02f);
00197   ne.setNormalSmoothingSize(10.0f);
00198   ne.setDepthDependentSmoothing(true);
00199   ne.setInputCloud(p);
00200   ne.compute(*n3);
00201   cout << t.precisionStop() << "s\t for IntegralImage Estimation" << endl;
00202 */
00203 /*
00204   t.precisionStart();
00205   KdTreeFLANN<PointXYZRGB>::Ptr tree(new KdTreeFLANN<PointXYZRGB>);
00206   NormalEstimation<PointXYZRGB, Normal> ne;
00207   ne.setRadiusSearch(0.04);
00208   ne.setSearchMethod(tree);
00209   ne.setInputCloud(p);
00210   ne.compute(*n);
00211   cout << t.precisionStop() << "s\t for Normal Estimation" << endl;
00212 */
00213 
00214   t.precisionStart();
00215   cob_3d_features::OrganizedNormalEstimation<PointXYZRGB, Normal, PointLabel>one;
00216   one.setInputCloud(p);
00217   one.setOutputLabels(l);
00218   one.setPixelSearchRadius(radius_,1,circle_); //radius,pixel,circle
00219   one.setSkipDistantPointThreshold(th_);
00220   one.compute(*n);
00221   cout << t.precisionStop() << "s\t for Organized Normal Estimation" << endl;
00222 
00223   t.precisionStart();
00224   cob_3d_features::OrganizedCurvatureEstimation<PointXYZRGB,Normal,PointLabel,PrincipalCurvatures>oce;
00225   oce.setInputCloud(p);
00226   oce.setInputNormals(n);
00227   oce.setOutputLabels(l);
00228   oce.setPixelSearchRadius(radius_,1,circle_);
00229   oce.setSkipDistantPointThreshold(th_);
00230   oce.setEdgeClassThreshold(cmax_);
00231   oce.compute(*pc);
00232   cout << t.precisionStop() << "s\t for Organized Curvature Estimation" << endl;
00233 
00234   cob_3d_features::CurvatureClassifier<PrincipalCurvatures, PointLabel>cc;
00235   cc.setInputCloud(pc);
00236   cc.setUpperThreshold(upper_);
00237   cc.setLowerThreshold(lower_);
00238   cc.setMaxMinRatio(7.0);
00239   cc.classifyForSegmentation(*l);
00240 
00241   cout << "Colorize min max values" <<endl;
00242   float c_max = 0;
00243   float c_min = 100000;
00244 
00245 /*
00246   for (size_t i = 0; i < p->points.size(); i++)
00247   {
00248     c_max = std::max(n->points[i].curvature,c_max);
00249     c_min = std::min(n->points[i].curvature,c_min);
00250   }
00251 
00252   for (size_t i = 0; i < p->points.size(); i++)
00253   {
00254     int col = (n->points[i].curvature) / (cmax_) * 255;
00255     if (col > 255) col = 255;
00256     if (col < 0) col = 0;
00257     p->points[i].r = col;
00258     p->points[i].g = col;
00259     p->points[i].b = col;
00260   }
00261 */
00262   for (size_t i = 0; i < l->points.size(); i++)
00263   {
00264     applyColor(i, l, p);
00265   }
00266 
00267   visualization::PCLVisualizer v;
00268   ColorHdlRGB col_hdl(p);
00269   visualization::PointCloudColorHandlerCustom<PointXYZRGB> col_hdl_single (p, 255,0,0);
00270 //  ColorHdlRGB col_hdl2(p2);
00271 
00272   /* --- Viewports: ---
00273    *  1y
00274    *    | 1 | 3 |
00275    * .5 ----+----
00276    *    | 2 | 4 |
00277    *  0    .5    1x
00278    * 1:
00279    */
00280   // xmin, ymin, xmax, ymax
00281   int v1(0);
00282   v.createViewPort(0.0, 0.0, 0.5, 1.0, v1);
00283   v.setBackgroundColor(0,127,127, v1);
00284   v.addPointCloud<PointXYZRGB>(p, col_hdl, "segmented1", v1);
00285   //v.addPointCloudNormals<PointXYZRGB, Normal>(p,n,10,0.04,"normals1", v1);
00286 
00287   int v2(0);
00288   v.createViewPort(0.5, 0.0, 1.0, 1.0, v2);
00289   v.setBackgroundColor(0,127,127, v2);
00290 
00291   v.addPointCloud<PointXYZRGB>(p, col_hdl_single, "segmented2", v2);
00292   v.addPointCloudNormals<PointXYZRGB, Normal>(p,n,3,0.04,"normals2", v2);
00293 
00294   while(!v.wasStopped())
00295   {
00296     v.spinOnce(100);
00297     usleep(100000);
00298   }
00299 
00300   /*
00301   cv::Mat segmented;
00302   vector<PointIndices> clusters;
00303   cob_3d_mapping_features::Segmentation seg;
00304   seg.propagateWavefront2(l);
00305   seg.getClusterIndices(l, clusters, segmented);
00306   cv::imshow("segmented", segmented);
00307   cv::waitKey();
00308   */
00309 
00310   return(0);
00311 
00312 }


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