pcd点云地图转换为八叉树ot地图

pcd点云地图转换为八叉树ot地图

引言

参考高博博客

1.code

#include <iostream>
#include <assert.h>

//pcl
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

//octomap
#include <octomap/octomap.h>
#include <octomap/ColorOcTree.h>

using namespace std;

int main(int argc, char** argv)
{
    if(argc != 3) {
        cout << "Usage: pcd2colorOctomap <input_file> <output_file>" << endl;
        return -1;
    }

    string input_file = argv[1];
    string output_file = argv[2];
    pcl::PointCloud<pcl::PointXYZRGBA> cloud;
    pcl::io::loadPCDFile<pcl::PointXYZRGBA> (input_file, cloud);

    cout << "point cloud loaded, point size = " << cloud.points.size() << endl;

    //声明octomap变量
    cout << "copy data into octomap..." << endl;
    //创建带颜色的八叉树对象,参数为分辨率,这里设成了0.04
    octomap::ColorOcTree tree( 0.04 );

    for(auto p:cloud.points) {
        //将点云里的点插入到octomap中
        tree.updateNode(octomap::point3d(p.x, p.y, p.z), true);
    }

    //设置颜色
    for(auto p:cloud.points) {
        tree.integrateNodeColor(p.x, p.y, p.z, p.r, p.g, p.b);
    }

    //更新octomap
    tree.updateInnerOccupancy();
    //存储octomap, 注意要存成.ot文件而非.bt文件
    tree.write(output_file);
    cout << "done." << endl;

    return 0;
}

2.显示

pcl_viewer map.pcd
octovis map.ot

点云地图:

八叉树地图:

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值