00001
00063
00064 #include <opencv2/core/core.hpp>
00065 #include <cv.h>
00066 #include <highgui.h>
00067
00068
00069 #include <boost/program_options.hpp>
00070 #include <boost/timer.hpp>
00071
00072
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
00078
00079
00080
00081
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
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:
00141 col->points[i].r = 255;
00142 col->points[i].g = 0;
00143 col->points[i].b = 255;
00144 break;
00145 case I_CYL:
00146 col->points[i].r = 255;
00147 col->points[i].g = 255;
00148 col->points[i].b = 0;
00149 break;
00150 case I_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:
00156 col->points[i].r = 0;
00157 col->points[i].g = 255;
00158 col->points[i].b = 0;
00159 break;
00160 case I_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
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
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
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_);
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
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
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
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
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
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
00302
00303
00304
00305
00306
00307
00308
00309
00310 return(0);
00311
00312 }