Ubuntu下PCL_viewer查看每帧点云pcd格式

这篇文章展示了如何在C++中使用PointCloudLibrary(PCL)进行点云数据的读取、预处理和可视化,包括使用Octree、IntegralImageNormal、文件I/O和异常点过滤等技术。
摘要由CSDN通过智能技术生成
#include <pcl/point_cloud.h>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/octree/octree.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
#include <iostream>
#include <vector>
#include <ctime>
#include <pcl/io/ply_io.h>
#include <pcl/console/print.h>
#include <pcl/console/parse.h>
#include <pcl/console/time.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/io/vtk_io.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
//#include <io.h>
#include <dirent.h>
#include <filesystem>
#include <vector>
#include <sys/stat.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl/filters/conditional_removal.h>
#include <pcl/filters/filter.h>
#include <pcl/common/impl/io.hpp>
#include <pcl/filters/passthrough.h>
#include <thread>
//#include <pcl\filters\radius_outlier_removal.h>
#include <pcl/filters/voxel_grid.h>

using namespace pcl;
using namespace pcl::io;
using namespace pcl::console;
using namespace std;

void getFiles(const std::string& path, std::vector<std::string>& files) {
    DIR *dir;
    struct dirent *ent;
    struct stat st;

    dir = opendir(path.c_str());
    if (dir != NULL) {
        while ((ent = readdir(dir)) != NULL) {
            const std::string file_name = ent->d_name;
            const std::string full_file_path = path + "/" + file_name;
            if (file_name[0] == '.') {
                continue; // Skip hidden files
            }
            if (stat(full_file_path.c_str(), &st) == -1) {
                continue; // If unable to get file info, skip
            }
            if (S_ISDIR(st.st_mode)) {
                if (file_name != "." && file_name != "..") {
                    getFiles(full_file_path, files); // Recursively get files in subdirectories
                }
            } else {
                files.push_back(full_file_path); // Add file to the list
            }
        }
        closedir(dir);
    }
}
bool compareFiles(const std::string& file1, const std::string& file2) {
    // 提取文件名中的数字部分,并转换为整数进行比较
    int num1 = std::stoi(file1.substr((file1.find_last_of('/')+1), file1.find('.')));
    int num2 = std::stoi(file2.substr((file2.find_last_of('/')+1), file2.find('.')));
    
    return num1 < num2;
}

int main()
{
	vector<string> files;
	char * filePath = "/home/noetic/下载/Scans8";
	//获取该路径下的所有文件  
	getFiles(filePath, files);
	char str[30];
	std::sort(files.begin(), files.end(), compareFiles);
	pcl::visualization::PCLVisualizer viewer("PCL Viewer");
	viewer.setBackgroundColor(1.0, 1.0, 1.0);
	
	//for (int i = 0; i < size; i++)
	for (const auto& file : files)
	{
		cout << file.c_str() << endl;
		pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
		
		pcl::io::loadPCDFile(file, *cloud);
		std::string cloud_id = "cloud_" + file;
		pcl::visualization::PCLVisualizer viewer("PCL Viewer");
		viewer.setBackgroundColor(1.0, 1.0, 1.0);
		pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> cloud_source(cloud, 255, 0, 0);
		viewer.addPointCloud(cloud,cloud_source,cloud_id);
		viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, cloud_id);
		
		while (!viewer.wasStopped())
		{
			viewer.spinOnce(100);
		}

		viewer.removePointCloud(cloud_id);

		
	}
	return(0);
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值