PCL点云显示

Posted yinxingtianxia

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PCL点云显示相关的知识,希望对你有一定的参考价值。

利用pcl库来显示点云

1. CMakeLists.txt

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)  
  
project(show_pointcloud)  
  
find_package(PCL 1.7 REQUIRED)  
  
include_directories($PCL_INCLUDE_DIRS)  
link_directories($PCL_LIBRARY_DIRS)  
add_definitions($PCL_DEFINITIONS)  
  
add_executable (show_pointcloud show_pointcloud.cpp)  
target_link_libraries (show_pointcloud $PCL_LIBRARIES) 

2. show_pointcloud.cpp

    #include <pcl/visualization/cloud_viewer.h>  
    #include <iostream>  
    #include <pcl/io/io.h>  
    #include <pcl/io/pcd_io.h>  
          
    int user_data;  
          
    void   
    viewerOneOff (pcl::visualization::PCLVisualizer& viewer)  
      
        viewer.setBackgroundColor (1.0, 0.5, 1.0);
        pcl::PointXYZ o;  
        o.x = 1.0;  
        o.y = 0;  
        o.z = 0;  
        viewer.addSphere (o, 0.25, "sphere", 0);  
        std::cout << "i only run once" << std::endl;  
          
      
          
    void   
    viewerPsycho (pcl::visualization::PCLVisualizer& viewer)  
      
        static unsigned count = 0;  
        std::stringstream ss;  
        ss << "Once per viewer loop: " << count++;  
        viewer.removeShape ("text", 0);  
        viewer.addText (ss.str(), 200, 300, "text", 0);  
          
        //FIXME: possible race condition here:  
        user_data++;  
      
          
    int   
    main ()  
      
        pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);  
        pcl::io::loadPCDFile ("./../map.pcd", *cloud);
          
        pcl::visualization::CloudViewer viewer("Cloud Viewer");  
          
        //blocks until the cloud is actually rendered  
        viewer.showCloud(cloud);  
          
        //use the following functions to get access to the underlying more advanced/powerful  
        //PCLVisualizer  
          
        //This will only get called once  
        viewer.runOnVisualizationThreadOnce (viewerOneOff);  
          
        //This will get called once per visualization iteration  
        viewer.runOnVisualizationThread (viewerPsycho);  
        while (!viewer.wasStopped ())  
          
        //you can also do cool processing here  
        //FIXME: Note that this is running in a separate thread from viewerPsycho  
        //and you should guard against race conditions yourself...  
        user_data++;  
          
        return 0;  
      

3. 显示的结果


以上是关于PCL点云显示的主要内容,如果未能解决你的问题,请参考以下文章

点云文件有几百兆用pcl加载时显示失败

qt+pcl点云库

vs2010 点云 pcl运行错误error2019

PCL(点云库)中实时 kinect 数据的范围图像生成

PCL:Visualizer 可视化❤️自定义颜色显示

Pcl 点云有缩放怎么匹配