Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. using namespace cm;
  2. using namespace cv;
  3. using namespace std;
  4.  
  5. // All the objects needed
  6. pcl::PCDReader reader;
  7. pcl::PassThrough<PointT> pass;
  8. pcl::NormalEstimation<PointT, pcl::Normal> ne;
  9. pcl::SACSegmentationFromNormals<PointT, pcl::Normal> seg;
  10. pcl::PCDWriter writer;
  11. pcl::ExtractIndices<PointT> extract;
  12. pcl::ExtractIndices<pcl::Normal> extract_normals;
  13. pcl::search::KdTree<PointT>::Ptr tree (new pcl::search::KdTree<PointT> ());
  14.  
  15. // Datasets
  16. pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT>);
  17. pcl::PointCloud<PointT>::Ptr cloud_filtered (new pcl::PointCloud<PointT>),
  18. cloud_projected(new pcl::PointCloud<PointT>);
  19. pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
  20. pcl::PointCloud<PointT>::Ptr cloud_filtered2 (new pcl::PointCloud<PointT>);
  21. pcl::PointCloud<pcl::Normal>::Ptr cloud_normals2 (new pcl::PointCloud<pcl::Normal>);
  22. pcl::ModelCoefficients::Ptr coefficients_plane (new pcl::ModelCoefficients), coefficients_cylinder (new pcl::ModelCoefficients);
  23. pcl::PointIndices::Ptr inliers_plane (new pcl::PointIndices), inliers_cylinder (new pcl::PointIndices);
  24.  
  25. // Read in the cloud data
  26. reader.read ("dm2hm_right32.pcd", *cloud);
  27. std::cerr << "PointCloud has: " << cloud->points.size () << " data points." << std::endl;
  28.  
  29. // Build a passthrough filter to remove spurious NaNs
  30. pass.setInputCloud (cloud);
  31. pass.setFilterFieldName ("z");
  32. pass.setFilterLimits (-600 , 600);
  33. pass.filter (*cloud_filtered);
  34. std::cerr << "PointCloud after filtering has: " << cloud_filtered->points.size () << " data points." << std::endl;
  35.  
  36. // Estimate point normals
  37. ne.setSearchMethod (tree);
  38. ne.setInputCloud (cloud_filtered);
  39. ne.setKSearch (50);
  40. ne.compute (*cloud_normals);
  41.  
  42. // Create the segmentation object for the planar model and set all the parameters
  43. seg.setOptimizeCoefficients (true);
  44. seg.setModelType (pcl::SACMODEL_NORMAL_PLANE);
  45. seg.setNormalDistanceWeight (0.1);
  46. seg.setMethodType (pcl::SAC_RANSAC);
  47. seg.setMaxIterations (100);
  48. seg.setDistanceThreshold (20);
  49. seg.setEpsAngle(0.05320);
  50. seg.setInputCloud (cloud_filtered);
  51. seg.setInputNormals (cloud_normals);
  52. Eigen::Vector3f YAxis(0,1,0);
  53. seg.setAxis(YAxis);
  54. // Obtain the plane inliers and coefficients
  55. seg.segment (*inliers_plane, *coefficients_plane);
  56. std::cerr << "Plane coefficients: " << *coefficients_plane << std::endl;
  57.  
  58. // Extract the planar inliers from the input cloud
  59. extract.setInputCloud (cloud_filtered);
  60. extract.setIndices (inliers_plane);
  61. extract.setNegative (false);
  62.  
  63.  
  64.  
  65. // Write the planar inliers to disk
  66. pcl::PointCloud<PointT>::Ptr cloud_plane (new pcl::PointCloud<PointT> ());
  67. extract.filter (*cloud_plane);
  68. std::cerr << "PointCloud representing the planar component: " << cloud_plane->points.size () << " data points." << std::endl;
  69. pcl::ProjectInliers<pcl::PointXYZ> proj;
  70. proj.setModelType (pcl::SACMODEL_PLANE);
  71. proj.setIndices (inliers_plane);
  72. proj.setInputCloud (cloud_filtered);
  73. proj.setModelCoefficients (coefficients_plane);
  74. proj.filter (*cloud_projected);
  75. std::cerr << "PointCloud after projection has: "
  76. << cloud_projected->points.size () << " data points." << std::endl;
  77.  
  78. // Create a Concave Hull representation of the projected inliers
  79. pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_hull (new pcl::PointCloud<pcl::PointXYZ>);
  80. pcl::ConcaveHull<pcl::PointXYZ> chull;
  81. chull.setInputCloud (cloud_projected);
  82. chull.setAlpha (50);
  83. chull.reconstruct (*cloud_hull);
  84.  
  85.  
  86. std::cerr << "Concave hull has: " << cloud_hull->points.size ()
  87. << " data points." << std::endl;
  88.  
  89. writer.write ("table_scene_mug_stereo_textured_hull.pcd", *cloud_hull, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement