PCL 显示点云图像

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

 

 

代码:

#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;
}

 

posted @ 2021-09-27 13:48  Doron419  阅读(403)  评论(0编辑  收藏  举报