欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > pcl读取同一文件下的多个pcd点云

pcl读取同一文件下的多个pcd点云

2025/2/23 7:07:20 来源:https://blog.csdn.net/qq_39003748/article/details/139687031  浏览:    关键词:pcl读取同一文件下的多个pcd点云
#include <iostream>
#include <Eigen/Core>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/common/file_io.h> // 批量处理头文件using namespace std;int main()
{string pcd_path = (argc > 1) ? argv[1] : "../test_data/result_1/"; vector<string> vpcldir;pcl::getAllPcdFilesInDirectory(pcd_path,vpcldir); // 获取指定路径下的所有PCD文件for (int i = 0; i < vpcldir.size(); i++) {auto cloud = std::make_shared<pcl::PointCloud<PointI>>();//pcl::io::loadPCDFile(pcd_path + vpcldir[i], *cloud);if (pcl::io::loadPCDFile(pcd_path + vpcldir[i], *cloud) < 0){PCL_ERROR("Couldn't read file \n");system("pause");return -1;}
//        cout << pcd_path + vpcldir[i] << "    " << cloud->size() << endl;}return 0;
}

这里用到了pcl的函数getAllPcdFilesInDirectory,查看源码

void getAllPcdFilesInDirectory(const std::string& directory, std::vector<std::string>& file_names)
{boost::filesystem::path p(directory);if(boost::filesystem::is_directory(p)){for(const auto& entry : boost::make_iterator_range(boost::filesystem::directory_iterator(p), {})){if (boost::filesystem::is_regular_file(entry)){//修改这里的后缀名字  .pcd   改为想要获取文件的后缀名字,即可实现获取任何格式的文件if (entry.path().extension() == ".pcd")file_names.emplace_back(entry.path().filename().string());}}}else{std::cerr << "Given path is not a directory\n";return;}std::sort(file_names.begin(), file_names.end());
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词