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>
#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");
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");
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
使强度信息渲染点云颜色结果 提出地面后的强度渲染结果
|