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; }
------------------------------------------------------------------------------------------------------
作者:Doron419
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!