本文主要是介绍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"); // 设置点云大小,默认为1while (!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
使强度信息渲染点云颜色结果
提出地面后的强度渲染结果
这篇关于20、使强度信息渲染点云颜色的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!