2017-08-14 23 views
2

私は、PCLのポイントクラウドライブラリを使用して私の部屋のポイントクラウドのセグメント成長を実行しています。 色の雲は次のようになります。 colored cloud領域成長セグメンテーションクラスタが間違っていますか?

ご覧のとおり、ほとんどのクラスタは表面に沿って見えます。私はseparatedly各クラスタを表示するとき はしかし、これらの結果の一部を以下に示します。 results 1

results 2

明らかクラスタは色の雲と同じではありませんが、私は理由を理解いけません。 私は分離点群にクラスタを保存するために、このコードを使用しています:

//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); 
    } 

は、それが何か間違ったことをやっているか、地域の出力がセグメンテーションは、実際に右成長している私のコードですか?

乾杯

------------- EDIT -----------------

Hereは、点群であるIテストのために使用しています。ここで

は、チュートリアルのいずれかに類似した、セグメンテーションコードを成長させ、完全な領域である:

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; 
} 

答えて

0

だから私はちょうどそれがあった、それを考え出しましたあまりにも単純な私はそれを見ることができなかった。ごめんなさい。 ポイントをクラスタにコピーするときに、フィルタリングしたポイントクラウドの代わりに元のポイントクラウドを使用していました。おそらく私がこれを考えていないような結果をもたらすかもしれません。

ので、この:

cloud_cluster->push_back(
       point_cloud_ptr->at(clusters[i].indices[j])); 

はに交換する必要があります。

cloud_cluster->push_back(
       cloud_filtered->at(clusters[i].indices[j])); 

乾杯

0

このコードを試してみてください。

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); 
    } 
+0

こんにちは、答えに感謝を。しかし、私はそれを試して、結果は似ている、まだ私はなぜこれが起こっているのかわからない –

+0

うーん、あなたは問題を複製するコードの最小限の完全なバージョンを投稿することができますか?そしてポイントクラウドの例? – brad

+0

こんにちは、遅い回答申し訳ありませんが、コード(私のオリジナル)とポイントクラウドは現在ポストにあります –

関連する問題