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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值