As shown on the left is the original three-dimensional point cloud pcd format, the right projection surface data XOZ, Y is 0.
#include <iostream>
#include <pcl/filters/project_inliers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl/features/normal_3d.h>
#include <pcl/segmentation/extract_clusters.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/ModelCoefficients.h>
#include<cstdlib>
#include <windows.h>
#include <pcl/console/parse.h>
#include <pcl/console/print.h>
#include <pcl/correspondence.h>
#include <boost/filesystem.hpp>
using namespace pcl;
typedef PointXYZ PoinT;
int *rand_rgb()
{
//随机产生颜色
int *rgb = new int[3];
rgb[0] = rand() % 255;
rgb[1] = rand() % 255;
rgb[2] = rand() % 255;
return rgb;
}
int
main(int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_projected(new pcl::PointCloud<pcl::PointXYZ>);
//点云的读取*********************************************************
if (io::loadPCDFile("F://coutsaved//test//boxes//pcd//11Cloud.pcd", *cloud) == -1)
{
PCL_ERROR("read false");
return 0;
}
// Create a set of planar coefficients with X=Y=0,Z=1
//In this case, we use a plane model, with ax+by+cz+d=0, where a=b=d=0, and c=1, or said differently, the X-Y plane.
pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients());
coefficients->values.resize(4);
coefficients->values[0] = 0;
coefficients->values[1] = 1.0;
coefficients->values[2] = 0;
coefficients->values[3] = 0;
visualization::PCLVisualizer::Ptr viewer1(new visualization::PCLVisualizer("Remove-Y"));
// Create the filtering object
pcl::ProjectInliers<pcl::PointXYZ> proj;
proj.setModelType(pcl::SACMODEL_PLANE);
proj.setInputCloud(cloud);
proj.setModelCoefficients(coefficients);
proj.filter(*cloud_projected);
io::savePCDFileASCII("F://coutsaved//test//boxes//plane//removey.pcd", *cloud_projected);//保存投影到XOZ面上的点云
int *rgb = rand_rgb(); //随机生成0-255的颜色值
visualization::PointCloudColorHandlerCustom<PoinT>rgb1(cloud_projected, rgb[0], rgb[1], rgb[2]);
delete[]rgb;
viewer1->addPointCloud(cloud_projected, rgb1, "F://coutsaved//test//boxes//plane//removey.pcd");
system("pause");
return (0);
}