PCL中的点云压缩工具详解

官网教程:https://pcl.readthedocs.io/projects/tutorials/en/latest/compression.html#

代码例程

    bool compression_map(const std::string& inputFilePath, const std::string& outputFilePath, const double& downsample)
    {
        // pcl 读取点云地图
        pcl::PointCloud<pcl::PointXYZI>::Ptr globalMapCloud(new pcl::PointCloud<pcl::PointXYZI>);
        pcl::io::loadPCDFile(inputFilePath + "/x.pcd", *globalMapCloud);

        // pcl 点云地图降采样
        downSizeFilterCorner.setInputCloud(globalMapCloud);
        downSizeFilterCorner.setLeafSize(downsample, downsample, downsample);
        downSizeFilterCorner.filter(*globalMapCloud);

        // pcl 压缩点云地图为 .bin 文件
        //=== 1. 将XYZI->XYZ ===
        pcl::PointCloud<pcl::PointXYZ>::Ptr globalMapCloud_xyz(new pcl::PointCloud<pcl::PointXYZ>);
        pcl::copyPointCloud(*globalMapCloud, *globalMapCloud_xyz);
        //=== 2. 压缩为bin文件
        bool showStatistics = true;
        pcl::io::compression_Profiles_e compressionProfile = pcl::io::MED_RES_ONLINE_COMPRESSION_WITHOUT_COLOR;
        pcl::io::OctreePointCloudCompression<pcl::PointXYZ> *OctreeCompression;
        OctreeCompression = new pcl::io::OctreePointCloudCompression<pcl::PointXYZ>(compressionProfile, showStatistics);
        std::stringstream compressedData;
        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out(new pcl::PointCloud<pcl::PointXYZ>);
        OctreeCompression->encodePointCloud(globalMapCloud_xyz, compressedData);
        ofstream outFile(outputFilePath + "/x.bin", ios::binary);
        outFile << compressedData.rdbuf();
        outFile.close();
        delete OctreeCompression;
        return true;
    }

其中需要注意pcl提供了压缩的参数设定接口,简单的可以直接使用其提供的几种常用模板:

cubic centimeter resolution:立方厘米的分辨率
cubic millimeter resolution:立方毫米的分辨率
fast online encoding:在线压缩
efficient offline encoding:离线压缩

LOW_RES_ONLINE_COMPRESSION_WITHOUT_COLOR 1 cubic centimeter resolution, no color, fast online encoding

LOW_RES_ONLINE_COMPRESSION_WITH_COLOR 1 cubic centimeter resolution, color, fast online encoding

MED_RES_ONLINE_COMPRESSION_WITHOUT_COLOR 5 cubic millimeter resolution, no color, fast online encoding

MED_RES_ONLINE_COMPRESSION_WITH_COLOR 5 cubic millimeter resolution, color, fast online encoding

HIGH_RES_ONLINE_COMPRESSION_WITHOUT_COLOR 1 cubic millimeter resolution, no color, fast online encoding

HIGH_RES_ONLINE_COMPRESSION_WITH_COLOR 1 cubic millimeter resolution, color, fast online encoding

LOW_RES_OFFLINE_COMPRESSION_WITHOUT_COLOR 1 cubic centimeter resolution, no color, efficient offline encoding

LOW_RES_OFFLINE_COMPRESSION_WITH_COLOR 1 cubic centimeter resolution, color, efficient offline encoding

MED_RES_OFFLINE_COMPRESSION_WITHOUT_COLOR 5 cubic millimeter resolution, no color, efficient offline encoding

MED_RES_OFFLINE_COMPRESSION_WITH_COLOR 5 cubic millimeter resolution, color, efficient offline encoding

HIGH_RES_OFFLINE_COMPRESSION_WITHOUT_COLOR 1 cubic millimeter resolution, no color, efficient offline encoding

HIGH_RES_OFFLINE_COMPRESSION_WITH_COLOR 1 cubic millimeter resolution, color, efficient offline encoding

MANUAL_CONFIGURATION :支持手动调整参数

手动调整参数:

OctreePointCloudCompression (compression_Profiles_e compressionProfile_arg,
                             bool showStatistics_arg,
                             const double pointResolution_arg,
                             const double octreeResolution_arg,
                             bool doVoxelGridDownDownSampling_arg,
                             const unsigned int iFrameRate_arg,
                             bool doColorEncoding_arg,
                             const unsigned char colorBitResolution_arg
                            )

1. compressionProfile_arg 需要设置为MANUAL_CONFIGURATION模式
2. showStatistics_arg 打印压缩的相关信息:压缩率等
3. pointResolution_arg:定义点坐标的编码精度。此参数应设置为低于传感器噪声的值
4. octreeResolution_arg:八叉树体素大小,体素小则耗时,但性能高
5. doVoxelGridDownDownSampling_arg: 若为true,则根据八叉树分辨率相应进行下采样
6. iFrameRate_arg: 点云压缩方案对点云进行差分编码。通过这种方式,对传入点云和先前编码的点云之间的差异进行编码,以实现最大的压缩性能(看这个意思像是会比较传入点云的差异,对不同的地方进行压缩编码)
7. doColorEncoding_arg: 是不是带颜色的
8. colorBitResolution_arg: 定义要编码的每个颜色分量的位数
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值