summary : Project the point cloud onto a model , Take the plane as an example .

code :
#include <iostream> #include <pcl/point_types.h> #include <pcl/io/pcd_io.h>
#include <pcl/ModelCoefficients.h>// Model parameter definition header file #include
<pcl/filters/project_inliers.h>// Projection filtering class header file #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();
// Create a coefficient of X=Y=0,Z=1 The plane of 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; // Create filter object 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; }
  visualization :

 

Technology
©2019-2020 Toolsou All rights reserved,
Digital rolling lottery program Keras Save and load model (JSON+HDF5) Remember once EventBus Project issues caused by memory leaks I've been drinking soft water for three years ? What is the use of soft water and water softener msf Generate Trojan horse attack android mobile phone Time conversion front desk will 2020-07-17T03:07:02.000+0000 Into 2020-07-17 11:07:02 Chuan Shen 1190 Reverses the substring between each pair of parentheses leetcodehive Summary of processing methods for a large number of small files SparkSQL Achieve partition overlay write Image format conversion