在一些情況下,我們想要驗證算法對一系列pcd數據的魯棒性,你可以選擇一幀一幀加載PCD文件,但相對比較麻煩,因此以下程序展示瞭如何進行點雲數據流的處理。
pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
ProcessPointClouds<pcl::PointXYZI>* pointProcessorI = new ProcessPointClouds<pcl::PointXYZI>();
std::vector<boost::filesystem::path> stream = pointProcessorI->streamPcd("../pcd");
auto streamIterator = stream.begin(); //pcd爲存放一系列點雲的文件
pcl::PointCloud<pcl::PointXYZI>::Ptr inputCloudI;
while (!viewer->wasStopped ())
{
inputCloudI = pointProcessorI->loadPcd((*streamIterator).string());
//算法處理
streamIterator++;
if(streamIterator == stream.end())
streamIterator = stream.begin();
viewer->spinOnce ();
}
上面用到的streamPcd定義如下:
template<typename PointT>
std::vector<boost::filesystem::path> ProcessPointClouds<PointT>::streamPcd(std::string dataPath)
{
std::vector<boost::filesystem::path> paths(boost::filesystem::directory_iterator{dataPath}, boost::filesystem::directory_iterator{});
sort(paths.begin(), paths.end());
return paths;
}