Go to the documentation of this file.00001 #include <ros/ros.h>
00002
00003 #include <pcl/point_types.h>
00004 #include <pcl_ros/point_cloud.h>
00005 #include "cob_3d_mapping_common/point_types.h"
00006 #include "cob_3d_segmentation/impl/fast_segmentation.hpp"
00007 #include "cob_3d_features/organized_normal_estimation_omp.h"
00008
00009
00010
00011 typedef cob_3d_segmentation::FastSegmentation<
00012 pcl::PointXYZRGB,
00013 pcl::Normal,
00014 PointLabel> Segmentation3d;
00015 typedef cob_3d_features::OrganizedNormalEstimationOMP<
00016 pcl::PointXYZRGB,
00017 pcl::Normal,
00018 PointLabel> NormalEstimation;
00019
00020 void cloud_cb(const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& input)
00021 {
00022
00023 pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
00024 pcl::PointCloud<PointLabel>::Ptr labels(new pcl::PointCloud<PointLabel>);
00025
00026
00027 NormalEstimation one;
00028
00029
00030 one.setOutputLabels(labels);
00031
00032 one.setPixelSearchRadius(8,2,2);
00033
00034 one.setSkipDistantPointThreshold(8);
00035 one.setInputCloud(input);
00036 one.compute(*normals);
00037
00038 Segmentation3d seg;
00039 seg.setNormalCloudIn(normals);
00040
00041 seg.setLabelCloudInOut(labels);
00042
00043 seg.setSeedMethod(cob_3d_segmentation::SEED_RANDOM);
00044 seg.setInputCloud(input);
00045 seg.compute();
00046
00047
00048
00049
00050 pcl::PointCloud<pcl::PointXYZRGB>::Ptr points(
00051 new pcl::PointCloud<pcl::PointXYZRGB>);
00052 *points = *input;
00053 seg.mapSegmentColor(points);
00054
00055
00056 for(size_t i = 0; i<labels->size(); ++i)
00057 {
00058 int cluster_id = labels->points[i].label;
00059 }
00060
00061
00062
00063
00064 Segmentation3d::ClusterHdlPtr cluster_handler = seg.clusters();
00065
00066 Segmentation3d::ClusterPtr c = cluster_handler->begin();
00067 for(; c != cluster_handler->end(); ++c)
00068 {
00069
00070
00071 int size = c->size();
00072
00073 Eigen::Vector3f mean = c->getCentroid();
00074
00075 Eigen::Vector3f orientation = c->getOrientation();
00076
00077 Eigen::Vector3i mean_color = c->getMeanColorVector();
00078
00079 Eigen::Vector3i dom_color = c->computeDominantColorVector();
00080
00081 std::vector<cob_3d_segmentation::PolygonPoint> border = c->border_points;
00082
00083 cluster_handler->computeClusterComponents(c);
00084 Eigen::Vector3f v1 = c->pca_point_comp1;
00085 Eigen::Vector3f v2 = c->pca_point_comp2;
00086 Eigen::Vector3f v3 = c->pca_point_comp3;
00087 Eigen::Vector3f values = c->pca_point_values;
00088
00089 std::vector<int>::iterator it = c->begin();
00090 for (; it != c->end(); ++it)
00091 {
00092
00093 pcl::PointXYZRGB p = input->points[*it];
00094 }
00095 }
00096
00097 int cluster_id = 20;
00098 c = cluster_handler->getCluster(cluster_id);
00099 }
00100
00101
00102 int main(int argc, char** argv)
00103 {
00104
00105 ros::init(argc,argv,"fast_segmentation_tutorial");
00106 ros::NodeHandle nh;
00107
00108
00109 ros::Subscriber sub = nh.subscribe ("input", 1, cloud_cb);
00110
00111
00112 ros::spin ();
00113 }