• PCL可视化点云【颜色特征】


    以颜色区别深度

    为了更加直观的显示点云,将不同的深度值显示为不同的颜色。

    #include <iostream>
    #include <pcl/point_types.h>
    #include <pcl/io/ply_io.h>
    #include <pcl/visualization/pcl_visualizer.h>
    #include <pcl/io/io.h>
    
    using namespace std;
    using namespace pcl;
    using namespace io;
    
    int main() {
        PointCloud<PointXYZ>::Ptr cloud(new PointCloud<PointXYZ>);
    
        if (io::loadPLYFile("bunny.ply", *cloud) == -1) { // 读取.ply文件
            cerr << "can't read file bunny.pcd" << endl;
            return -1;
        }
    
        boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    
        pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> fildColor(cloud, "z"); // 按照z字段进行渲染
        
        viewer->addPointCloud<pcl::PointXYZ>(cloud, fildColor, "sample cloud");
        viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud"); // 设置点云大小
    
        while (!viewer->wasStopped())
        {
            viewer->spinOnce(100);
            boost::this_thread::sleep(boost::posix_time::microseconds(100000));
        }
    
        return 0;
    }

    结果

    自定义颜色特征

    /*
        任何点云格式均可,不要求点云带有RGB字段
    */
    #include <iostream>
    #include <pcl/point_types.h>
    #include <pcl/io/ply_io.h>
    #include <pcl/visualization/pcl_visualizer.h>
    #include <pcl/io/io.h>
    
    using namespace std;
    using namespace pcl;
    using namespace io;
    
    int main() {
        PointCloud<PointXYZ>::Ptr cloud(new PointCloud<PointXYZ>);
    
        if (io::loadPLYFile("bunny.ply", *cloud) == -1) { // 读取.ply文件
            cerr << "can't read file bunny.pcd" << endl;
            return -1;
        }
    
        boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
        
        pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(cloud, 0, 255, 0); // green
        
        viewer->addPointCloud<pcl::PointXYZ>(cloud, single_color, "sample cloud");
    
        while (!viewer->wasStopped())
        {
            viewer->spinOnce(100);
            boost::this_thread::sleep(boost::posix_time::microseconds(100000));
        }
        return 0;
    }

    结果

     

  • 相关阅读:
    socket学习笔记——获取域名与IP(linux)
    socket学习笔记——实现收发文件(Windows)
    socket学习笔记——IO口的基本操作(读、写)
    Microsoft Visual C++ 2010(86) Redistributable不能安装完美解决
    AD转换精度的计算
    cuda编程基础
    CUDA中并行规约(Parallel Reduction)的优化
    Warp divergence
    提取图片中文字
    GPU基本概念详解
  • 原文地址:https://www.cnblogs.com/cvwyh/p/10405995.html
Copyright © 2020-2023  润新知