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

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

#include
#include
#include
#include
#include

using namespace std;
using namespace pcl;
using namespace io;

int main() {
PointCloud::Ptr cloud(new PointCloud);

if (io::loadPLYFile("bunny.ply", *cloud) == -1) { // 读取.ply文件
    cerr << "can't read file bunny.pcd" << endl;
    return -1;
}

boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));

pcl::visualization::PointCloudColorHandlerGenericField fildColor(cloud, "z"); // 按照z字段进行渲染

viewer->addPointCloud(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;

}
PCL可视化点云【颜色特征】_第1张图片
自定义颜色特征

/*
任何点云格式均可,不要求点云带有RGB字段
*/
#include
#include
#include
#include
#include

using namespace std;
using namespace pcl;
using namespace io;

int main() {
PointCloud::Ptr cloud(new PointCloud);

if (io::loadPLYFile("bunny.ply", *cloud) == -1) { // 读取.ply文件
    cerr << "can't read file bunny.pcd" << endl;
    return -1;
}

boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));

pcl::visualization::PointCloudColorHandlerCustom single_color(cloud, 0, 255, 0); // green

viewer->addPointCloud(cloud, single_color, "sample cloud");

while (!viewer->wasStopped())
{
    viewer->spinOnce(100);
    boost::this_thread::sleep(boost::posix_time::microseconds(100000));
}
return 0;

}
PCL可视化点云【颜色特征】_第2张图片

转载 https://www.cnblogs.com/cvwyh/p/10405995.html

你可能感兴趣的:(PCL)