我正在通過PCL點雲庫執行區域增長分割我的房間點雲。 彩色雲看起來如下: 區域增長分割簇是錯誤的?
正如你可以看到大部分的集羣看上去根據表面。 然而,當我告訴每個集羣separatedly,這些都是一些結果:
顯然簇不一樣的顏色的雲,但我不明白爲什麼。 我使用這個代碼到集羣存儲到分開的點雲:
//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;
}
您好,感謝答案。但是,我已經嘗試過了,結果是相似的,但我不明白爲什麼會發生這種情況 –
嗯,你可以發佈你的最小和完整版本的代碼複製問題?示例點雲? – brad
嗨,對於遲到的答案抱歉,代碼(我的原創)和點雲現在在帖子中 –