概述:将点云投影到一个模型上,以平面为例。

代码:
#include <iostream> #include <pcl/point_types.h> #include <pcl/io/pcd_io.h>
#include <pcl/ModelCoefficients.h>//模型参数定义头文件 #include
<pcl/filters/project_inliers.h>//投影滤波类头文件 #include
<pcl/visualization/pcl_visualizer.h> int main() { std::cout << "Hello, World!"
<< std::endl; pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in(new
pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr
cloud_out(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile("room_scan1.pcd",*cloud_in); std::cerr<<"Before
projection: "<<std::endl; for(size_t i = 0; i<cloud_in->size();i++)
std::cout<<" [ "<<i<<" ] , (
"<<cloud_in->points[i].x<<","<<cloud_in->points[i].y<<","<<cloud_in->points[i].z<<"
)"<<std::endl; std::cout<<"points: "<<cloud_in->points.size();
//创建一个系数为X=Y=0,Z=1的平面 pcl::ModelCoefficients::Ptr coefficients(new
pcl::ModelCoefficients()); coefficients->values.resize(4);
coefficients->values[0] = coefficients->values[1] = coefficients->values[3] =
0; coefficients->values[2] = 1; //创建滤波器对象 pcl::ProjectInliers<pcl::PointXYZ>
proj; proj.setModelType(pcl::SACMODEL_PLANE); proj.setInputCloud(cloud_in);
proj.setModelCoefficients(coefficients); proj.filter(*cloud_out);
std::cerr<<"Cloud after projection: "<<std::endl; for(size_t
i=0;i<cloud_out->points.size();i++) std::cout<<" [ "<<i<<" ] , (
"<<cloud_out->points[i].x<<","<<cloud_out->points[i].y<<","<<cloud_out->points[i].z<<"
)"<<std::endl; std::cout<<"points: "<<cloud_out->points.size(); //save
result_cloud pcl::io::savePCDFileASCII("cloud_projection.pcd",*cloud_out);
//visualizer pcl::visualization::PCLVisualizer::Ptr viewer(new
pcl::visualization::PCLVisualizer); viewer->initCameraParameters(); int v1(0);
viewer->createViewPort(0,0,0.5,1,v1); viewer->setBackgroundColor(128,128,0,v1);
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>
single_color1(cloud_in,255,0,255);
viewer->addPointCloud(cloud_in,single_color1,"cloud_in",v1); int v2(0);
viewer->createViewPort(0.5,0,1,1,v2); viewer->setBackgroundColor(0,255,0,v2);
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>
single_color2(cloud_out,223,45,55);
viewer->addPointCloud(cloud_out,single_color2,"cloud_out",v2);
viewer->addCoordinateSystem(); viewer->spin(); return 0; }
 可视化:

 

技术
©2019-2020 Toolsou All rights reserved,
一个名叫“讨火车”的小村子 终于把火车讨来了c++内存 指针越界检测机制_CrtMemBlockHeade错误总结-myBatis plus 分页记一次EventBus内存泄露导致的项目问题服务器价格有什么差异?Android中获取当前正在显示的Activity实例创建数据mysql库流程在Vue中使用Web Worker最优化方法总结:公式解、数值优化、求解思想使用easyPOI导入Excel数据