用PCL将文件夹下所有pcd存储成1个pcd文件

读取的文件夹路径是:/home/user/pcd/
生成的pcd文件名为:test_pcd.pcd

源码如下

#include <iostream>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/parse.h>
 
 
#include <string>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <iostream>
 using namespace std;
 
const char* path = "/media/car/T7/addpoint/data/";
void GetFileNames(string path,vector<string>& filenames)
{
    DIR *pDir;
    struct dirent* ptr;
    if(!(pDir = opendir(path.c_str()))){
        std::cout<<"Folder doesn't Exist!"<<std::endl;
        return;
    }
    while((ptr = readdir(pDir))!=0) {
        if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0){
            filenames.push_back(path + "/" + ptr->d_name);
            //std::cout<<path + "/" + ptr->d_name<<endl;
    }
    }
    closedir(pDir);
}
 
 
 
int main(int argc, char** argv) {
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloudadd(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	//pcl::io::loadPCDFile("./test1.pcd", *cloud);
 
 
	DIR *pDir;
    struct dirent* ptr;
    if(!(pDir = opendir("/home/user/pcd/"))){
        std::cout<<"Folder doesn't Exist!"<<std::endl;
        return -1;
    }
    while((ptr = readdir(pDir))!=0) {
        if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0){
            //filenames.push_back(path + "/" + ptr->d_name);
			pcl::io::loadPCDFile("/home/user/pcd/" + string(ptr->d_name), *cloud);
			*cloudadd = *cloudadd + *cloud;
			cloud->clear();
            //std::cout<<path + "/" + ptr->d_name<<endl;
    }
    }
    closedir(pDir);
 
	pcl::io::savePCDFileBinary("test_pcd.pcd", *cloudadd);
	return 0;
 
}

CMakeLists.txt如下

cmake_minimum_required(VERSION 2.8)
project(pcl_test)
 
# 设置编译模式
set( CMAKE_BUILD_TYPE "Debug" )
set(CMAKE_CXX_FLAGS   "-std=c++11")
set(PCL_DIR "/usr/share/pcl-1.9")
find_package(PCL)
 
 
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
 
add_executable(pcl_test addpoints.cpp)
 
target_link_libraries (pcl_test ${PCL_LIBRARIES} ${OpenCV_LIBS})
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值