20、使强度信息渲染点云颜色

PCD_ins.cpp

//头文件可能有冗余
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/io/ply_io.h>
#include <pcl/io/io.h>
#include<pcl/point_cloud.h>
#include<pcl/io/pcd_io.h>//which contains the required definitions to load and store point clouds to PCD and other file formats.
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/io/ply_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/io/io.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/filters/filter.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/passthrough.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/crop_box.h>
 
using namespace std;
using namespace pcl;
using namespace io;
 
void ground_filter(const pcl::PointCloud<pcl::PointXYZI>::Ptr& pc_in, pcl::PointCloud<pcl::PointXYZI>::Ptr& pc_out){
    pcl::PassThrough<pcl::PointXYZI> pass;
    pass.setInputCloud (pc_in);
    pass.setFilterFieldName ("z");
    pass.setFilterLimits (-0.9, 30.0);
    pass.filter (*pc_out);
}

int main() {
	PointCloud<PointXYZI>::Ptr cloud(new PointCloud<PointXYZI>);
	PointCloud<PointXYZI>::Ptr cloud_out(new PointCloud<PointXYZI>);
 
	if (io::loadPCDFile("/home/sweetorange/octomaps/octomap_a/octomap_tutor-master/data/sample.pcd", *cloud) == -1)
        { 
		cerr << "can't read file bunny.pcd" << endl;
		return -1;
	}
        ground_filter(cloud,cloud_out);
        cloud = cloud_out;
 
	shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
	viewer->setBackgroundColor(0, 0, 0);
	viewer->setWindowName("Point clouds are shown by intensity"); 
        // 按照intensity字段进行渲染
	pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZI> fildColor(cloud,"intensity");
	viewer->addPointCloud<pcl::PointXYZI>(cloud,fildColor,"sample cloud");

        viewer->addText("Point clouds are shown by intensity", 50, 50,0,1,0, "v1_text");
	//viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud"); // 设置点云大小,默认为1
 
	while (!viewer->wasStopped())
	{
		viewer->spinOnce(100);
		boost::this_thread::sleep(boost::posix_time::microseconds(100000));
	}
 
	return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)
project(PCD_ins)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")
add_compile_options(-std=c++11)
find_package(PCL 1.9 REQUIRED)
 
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})


add_executable(PCD_ins PCD_ins.cpp)

target_link_libraries (PCD_ins ${PCL_LIBRARIES})
 
install(TARGETS PCD_ins RUNTIME DESTINATION bin)

终端执行:

mkdir build
cd build
cmake ..
make
./PCD_ins

使强度信息渲染点云颜色结果
在这里插入图片描述
提出地面后的强度渲染结果提出地面后的强度渲染

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

甜橙の学习笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值