region_grow.cpp
Go to the documentation of this file.
00001 /*
00002  * region_grow.cpp
00003  *
00004  *  Created on: May 30, 2012
00005  *      Author: vsu
00006  */
00007 
00008 #include <pcl17/console/parse.h>
00009 #include <pcl17/io/pcd_io.h>
00010 #include <pcl17/search/kdtree.h>
00011 #include <pcl17/surface/mls.h>
00012 #include <pcl17/segmentation/region_growing_rgb.h>
00013 #include <pcl17/features/normal_3d.h>
00014 #include <pcl17/visualization/pcl_visualizer.h>
00015 #include <pcl17/filters/voxel_grid.h>
00016 
00017 int main(int argc, char **argv)
00018 {
00019   if (argc < 3)
00020   {
00021     PCL_INFO ("Usage %s -input_file cloud.pcd -distance_thresh 0.01 -angle_thresh 30 \n", argv[0]);
00022 
00023     return -1;
00024   }
00025 
00026   std::string filename;
00027   float distance_thresh = 0.01;
00028   float angle_thresh = 0.01;
00029 
00030   pcl17::console::parse_argument(argc, argv, "-input_file", filename);
00031   pcl17::console::parse_argument(argc, argv, "-distance_thresh", distance_thresh);
00032   pcl17::console::parse_argument(argc, argv, "-angle_thresh", distance_thresh);
00033 
00034   pcl17::PointCloud<pcl17::PointXYZRGBA>::Ptr cloud_orig(new pcl17::PointCloud<pcl17::PointXYZRGBA>);
00035   pcl17::PointCloud<pcl17::PointXYZRGBA>::Ptr cloud(new pcl17::PointCloud<pcl17::PointXYZRGBA>);
00036   pcl17::PointCloud<pcl17::Normal>::Ptr cloud_normals(new pcl17::PointCloud<pcl17::Normal>());
00037   pcl17::io::loadPCDFile(filename, *cloud);
00038 
00039   std::cerr << "Loaded file" << std::endl;
00040 
00041   //pcl17::VoxelGrid<pcl17::PointXYZRGBA> grid;
00042   //grid.setInputCloud(cloud_orig);
00043   //grid.setLeafSize(0.01f, 0.01f, 0.01f);
00044   //grid.filter(*cloud);
00045 
00046   // Create a KD-Tree
00047   pcl17::search::KdTree<pcl17::PointXYZRGBA>::Ptr tree(new pcl17::search::KdTree<pcl17::PointXYZRGBA>);
00048 
00049   std::cerr << "Created tree" << std::endl;
00050 
00051   pcl17::NormalEstimation<pcl17::PointXYZRGBA, pcl17::Normal> ne;
00052   ne.setInputCloud(cloud);
00053   ne.setSearchMethod(tree);
00054   ne.setRadiusSearch(0.01);
00055   ne.compute(*cloud_normals);
00056 
00057   std::cerr << "Computed normals" << std::endl;
00058 
00059   pcl17::RegionGrowingRGB<pcl17::PointXYZRGBA> region_growing;
00060   region_growing.setCloud(cloud);
00061   region_growing.setNormals(cloud_normals);
00062   region_growing.setNeighbourSearchMethod(tree);
00063 
00064   region_growing.setResidualTest(true);
00065   region_growing.setResidualThreshold(distance_thresh);
00066 
00067   region_growing.setCurvatureTest(true);
00068   region_growing.setCurvatureThreshold(0.04);
00069 
00070 
00071   region_growing.setSmoothMode(false);
00072   region_growing.setSmoothnessThreshold(angle_thresh * M_PI/180);
00073 
00074   region_growing.setPointColorThreshold(100.0);
00075   region_growing.setRegionColorThreshold(200.0);
00076 
00077   region_growing.segmentPoints();
00078 
00079   pcl17::PointCloud<pcl17::PointXYZRGB>::Ptr segments;
00080   segments = region_growing.getColoredCloud();
00081 
00082   pcl17::io::savePCDFile("result.pcd", *segments);
00083 
00084   pcl17::visualization::PCLVisualizer viz;
00085   viz.initCameraParameters();
00086 
00087   pcl17::visualization::PointCloudColorHandlerRGBField<pcl17::PointXYZRGB> rgb(segments);
00088   viz.addPointCloud<pcl17::PointXYZRGB> (segments, rgb);
00089   viz.spin();
00090 
00091   return 0;
00092 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


furniture_classification
Author(s): Vladyslav Usenko
autogenerated on Sun Oct 6 2013 12:12:34