在一些情况下,我们想要验证算法对一系列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;
}