PCL中显示点云

显示PLY和PCD文件的点云图像,效果图:

PCL中显示点云

 

 

代码:

#include<iostream>
#include<pcl/io/pcd_io.h>
#include<pcl/io/ply_io.h>
#include<pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>
#include <boost/thread/thread.hpp>

int main(int argc, char** argv) 
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

    if (pcl::io::loadPLYFile<pcl::PointXYZ>("liankou.ply", *cloud) == -1) //loadPCDFile 一样
    {
        PCL_ERROR("Couldn't read file rabbit.pcd\n");
        return(-1);
    }
    std::cout << cloud->points.size() << std::endl;
    boost::shared_ptr<pcl::visualization::PCLVisualizer>viewer(new pcl::visualization::PCLVisualizer("Show"));
    viewer->setBackgroundColor(0, 0, 0);

    // RGB三通道赋值
    pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>target_color(cloud, 255, 0, 0);
    viewer->addPointCloud<pcl::PointXYZ>(cloud, target_color, "test");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "test");

    while (!viewer->wasStopped())
    {
        viewer->spinOnce(100);

        boost::this_thread::sleep(boost::posix_time::microseconds(1000));
    }
    return 0;
}

 

上一篇:MedicalViewer 实例成员-方法


下一篇:[hadoop3.x系列]Hadoop常用文件存储格式及BigData File Viewer工具的使用(三)