2017-04-06 353 views
1

下面的函數不產生任何結果。換句話說,點雲中的點數與下采樣之前的點數完全相同。我嘗試了各種數字,從0.01到最後一個的葉子大小,但所有這些都產生了相同的結果。我不得不從pcl::PointCloud<T>pcl::PCLPointCloud2轉換(如下所示),所以我懷疑他們可能是這裏的問題。使用pcl :: VoxelGrid進行PCL降採樣

請讓我知道你是否有類似的問題,並解決它。 謝謝。

typedef pcl::PointCloud<pcl::PointXYZ>::Ptr PointCloudPtr; 

void PlantVis::downsample(PointCloudPtr cloud) { 
    pcl::PCLPointCloud2::Ptr cloud2(new pcl::PCLPointCloud2()); 
    pcl::toPCLPointCloud2(*cloud, *cloud2); 

    pcl::PCLPointCloud2::Ptr cloud_filtered(new pcl::PCLPointCloud2()); 

    pcl::VoxelGrid<pcl::PCLPointCloud2> sor; 
    sor.setInputCloud(cloud2); 
    sor.setLeafSize(500000000.01f, 500000000.01f, 500000000.01f); 
    sor.filter(*cloud_filtered); 

    pcl::PointCloud<pcl::PointXYZ>::Ptr m_cloud(new pcl::PointCloud<pcl::PointXYZ>); 
    pcl::fromPCLPointCloud2(*cloud_filtered, *m_cloud); 
    cloud = m_cloud; 
} 

回答

1

爲什麼你需要所有的轉換?試試這個:

void PlantVis::downsample(PointCloudPtr cloud) { 
    PointCloudPtr output(new pcl::PointCloud<pcl::PointXYZ>); 
    pcl::VoxelGrid<pcl::PointXYZ> sor; 
    sor.setInputCloud(input_cloud); 
    sor.setLeafSize(0.001f, 0.001f, 0.001f); 
    sor.filter(*output); 

    //display or do something else with output 
} 
+0

謝謝。你的代碼顯示了一些我以前忽略的東西。 – Illia

1

您的函數的參數是一個指針,即使您修改指針的值,原始雲不受影響。嘗試在功能定義中使用參考像這樣

void PlantVis::downsample(PointCloudPtr &cloud)