region growing segmentation clusters 错了吗?
Region growing segmentation clusters are wrong?
我正在通过 PCL 点云库对我房间的点云进行区域增长分割。
彩色云如下所示:
如您所见,大多数星团看起来都是根据表面。
但是,当我分别显示每个集群时,这些是一些结果:
很明显这些簇与彩色云中的不一样,但我不明白为什么。
我正在使用此代码将集群存储到分离的点云中:
//Store clusters into new pcls and all the clusters in an array of pcls
std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> clusters_pcl;
for (int i = 0; i < clusters.size(); ++i) {
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_cluster(
new pcl::PointCloud<pcl::PointXYZRGB>);
cloud_cluster->width = clusters[i].indices.size();
cloud_cluster->height = 1;
cloud_cluster->is_dense = true;
for (int j = 0; j < clusters[i].indices.size(); ++j) {
//Take the corresponding point of the filtered cloud from the indices for the new pcl
cloud_cluster->push_back(
point_cloud_ptr->at(clusters[i].indices[j]));
}
indices2.clear();
//pcl::removeNaNFromPointCloud(*cloud_cluster, *cloud_cluster, indices2);
clusters_pcl.push_back(cloud_cluster);
}
是我的代码做错了什么还是区域增长分割的输出实际上是正确的?
干杯
------------编辑----------------
Here 是我用于测试的点云。
这里是完整的区域增长分割代码,和教程中的代码类似:
std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> region_growing_segmentation(
pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr) {
pcl::PointCloud<pcl::PointXYZRGB>& point_cloud = *point_cloud_ptr;
std::vector<int> indices2;
// Create the filtering object: downsample the dataset using a leaf size of 1cm
pcl::VoxelGrid<pcl::PointXYZRGB> vg;
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(
new pcl::PointCloud<pcl::PointXYZRGB>);
vg.setInputCloud(point_cloud_ptr);
vg.setLeafSize(0.025f, 0.025f, 0.025f);
vg.filter(*cloud_filtered);
std::cout << "PointCloud after filtering has: "
<< cloud_filtered->points.size() << " data points." << std::endl;
pcl::search::Search<pcl::PointXYZRGB>::Ptr tree = boost::shared_ptr<
pcl::search::Search<pcl::PointXYZRGB> >(
new pcl::search::KdTree<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
pcl::NormalEstimation<pcl::PointXYZRGB, pcl::Normal> normal_estimator;
normal_estimator.setSearchMethod(tree);
normal_estimator.setInputCloud(cloud_filtered);
normal_estimator.setKSearch(50);
normal_estimator.compute(*normals);
pcl::RegionGrowing<pcl::PointXYZRGB, pcl::Normal> reg;
reg.setMinClusterSize(50);
reg.setMaxClusterSize(1000000);
reg.setSearchMethod(tree);
reg.setNumberOfNeighbours(100);
reg.setInputCloud(cloud_filtered);
reg.setInputNormals(normals);
reg.setSmoothnessThreshold(5.0 / 180.0 * M_PI);
reg.setCurvatureThreshold(1);
std::vector<pcl::PointIndices> clusters;
reg.extract(clusters);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr colored_cloud =
reg.getColoredCloud();
pcl::visualization::CloudViewer viewer("Cluster viewer");
viewer.showCloud(colored_cloud);
while (!viewer.wasStopped()) {
}
std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> clusters_pcl;
for (int i = 0; i < clusters.size(); ++i) {
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_cluster(
new pcl::PointCloud<pcl::PointXYZRGB>);
cloud_cluster->width = clusters[i].indices.size();
cloud_cluster->height = 1;
cloud_cluster->is_dense = true;
for (int j = 0; j < clusters[i].indices.size(); ++j) {
//Take the corresponding point of the filtered cloud from the indices for the new pcl
cloud_cluster->push_back(
point_cloud_ptr->at(clusters[i].indices[j]));
}
indices2.clear();
//pcl::removeNaNFromPointCloud(*cloud_cluster, *cloud_cluster, indices2);
clusters_pcl.push_back(cloud_cluster);
}
return clusters_pcl;
}
试试这个代码:
pcl::ExtractIndices<pcl::PointXYZRGB> extract;
std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> output_clouds; //vector of point clouds that will hold the cluster clouds
for (int i = 0; i < clusters.size(); ++i){
upcloud cloud_temp(new pcl::PointCloud<pcl::PointXYZRGB>);
//extract the cloud from the cluster indicies
extract.setInputCloud(input_cloud);
pcl::PointIndices cluster = clusters[i];
boost::shared_ptr<pcl::PointIndices> indicies = boost::make_shared<pcl::PointIndices>(cluster);
extract.setIndices(indicies);
extract.setNegative(false);
extract.filter(*cloud_temp);
output_clouds.push_back(cloud_temp);
}
所以我就想通了,太简单了看不出来;对不起。
当我将点复制到簇中时,我使用的是原始点云而不是过滤后的点云。也许结果是这样的,我什至没有想到这一点。
所以这个:
cloud_cluster->push_back(
point_cloud_ptr->at(clusters[i].indices[j]));
必须替换为:
cloud_cluster->push_back(
cloud_filtered->at(clusters[i].indices[j]));
干杯
我正在通过 PCL 点云库对我房间的点云进行区域增长分割。
彩色云如下所示:
如您所见,大多数星团看起来都是根据表面。
但是,当我分别显示每个集群时,这些是一些结果:
很明显这些簇与彩色云中的不一样,但我不明白为什么。 我正在使用此代码将集群存储到分离的点云中:
//Store clusters into new pcls and all the clusters in an array of pcls
std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> clusters_pcl;
for (int i = 0; i < clusters.size(); ++i) {
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_cluster(
new pcl::PointCloud<pcl::PointXYZRGB>);
cloud_cluster->width = clusters[i].indices.size();
cloud_cluster->height = 1;
cloud_cluster->is_dense = true;
for (int j = 0; j < clusters[i].indices.size(); ++j) {
//Take the corresponding point of the filtered cloud from the indices for the new pcl
cloud_cluster->push_back(
point_cloud_ptr->at(clusters[i].indices[j]));
}
indices2.clear();
//pcl::removeNaNFromPointCloud(*cloud_cluster, *cloud_cluster, indices2);
clusters_pcl.push_back(cloud_cluster);
}
是我的代码做错了什么还是区域增长分割的输出实际上是正确的?
干杯
------------编辑----------------
Here 是我用于测试的点云。
这里是完整的区域增长分割代码,和教程中的代码类似:
std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> region_growing_segmentation(
pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr) {
pcl::PointCloud<pcl::PointXYZRGB>& point_cloud = *point_cloud_ptr;
std::vector<int> indices2;
// Create the filtering object: downsample the dataset using a leaf size of 1cm
pcl::VoxelGrid<pcl::PointXYZRGB> vg;
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(
new pcl::PointCloud<pcl::PointXYZRGB>);
vg.setInputCloud(point_cloud_ptr);
vg.setLeafSize(0.025f, 0.025f, 0.025f);
vg.filter(*cloud_filtered);
std::cout << "PointCloud after filtering has: "
<< cloud_filtered->points.size() << " data points." << std::endl;
pcl::search::Search<pcl::PointXYZRGB>::Ptr tree = boost::shared_ptr<
pcl::search::Search<pcl::PointXYZRGB> >(
new pcl::search::KdTree<pcl::PointXYZRGB>);
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
pcl::NormalEstimation<pcl::PointXYZRGB, pcl::Normal> normal_estimator;
normal_estimator.setSearchMethod(tree);
normal_estimator.setInputCloud(cloud_filtered);
normal_estimator.setKSearch(50);
normal_estimator.compute(*normals);
pcl::RegionGrowing<pcl::PointXYZRGB, pcl::Normal> reg;
reg.setMinClusterSize(50);
reg.setMaxClusterSize(1000000);
reg.setSearchMethod(tree);
reg.setNumberOfNeighbours(100);
reg.setInputCloud(cloud_filtered);
reg.setInputNormals(normals);
reg.setSmoothnessThreshold(5.0 / 180.0 * M_PI);
reg.setCurvatureThreshold(1);
std::vector<pcl::PointIndices> clusters;
reg.extract(clusters);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr colored_cloud =
reg.getColoredCloud();
pcl::visualization::CloudViewer viewer("Cluster viewer");
viewer.showCloud(colored_cloud);
while (!viewer.wasStopped()) {
}
std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> clusters_pcl;
for (int i = 0; i < clusters.size(); ++i) {
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_cluster(
new pcl::PointCloud<pcl::PointXYZRGB>);
cloud_cluster->width = clusters[i].indices.size();
cloud_cluster->height = 1;
cloud_cluster->is_dense = true;
for (int j = 0; j < clusters[i].indices.size(); ++j) {
//Take the corresponding point of the filtered cloud from the indices for the new pcl
cloud_cluster->push_back(
point_cloud_ptr->at(clusters[i].indices[j]));
}
indices2.clear();
//pcl::removeNaNFromPointCloud(*cloud_cluster, *cloud_cluster, indices2);
clusters_pcl.push_back(cloud_cluster);
}
return clusters_pcl;
}
试试这个代码:
pcl::ExtractIndices<pcl::PointXYZRGB> extract;
std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> output_clouds; //vector of point clouds that will hold the cluster clouds
for (int i = 0; i < clusters.size(); ++i){
upcloud cloud_temp(new pcl::PointCloud<pcl::PointXYZRGB>);
//extract the cloud from the cluster indicies
extract.setInputCloud(input_cloud);
pcl::PointIndices cluster = clusters[i];
boost::shared_ptr<pcl::PointIndices> indicies = boost::make_shared<pcl::PointIndices>(cluster);
extract.setIndices(indicies);
extract.setNegative(false);
extract.filter(*cloud_temp);
output_clouds.push_back(cloud_temp);
}
所以我就想通了,太简单了看不出来;对不起。 当我将点复制到簇中时,我使用的是原始点云而不是过滤后的点云。也许结果是这样的,我什至没有想到这一点。
所以这个:
cloud_cluster->push_back(
point_cloud_ptr->at(clusters[i].indices[j]));
必须替换为:
cloud_cluster->push_back(
cloud_filtered->at(clusters[i].indices[j]));
干杯