code show as below:
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/filters/project_inliers.h>
#include<stdio.h>
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>);
// Fill in the cloud data
cloud->width = 5;
cloud->height = 1;
cloud->points.resize(cloud->width * cloud->height);
for (size_t i = 0; i < cloud->points.size(); ++i)
{
cloud->points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
cloud->points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
cloud->points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
}
std::cerr << "Cloud before projection: " << std::endl;
for (size_t i = 0; i < cloud->points.size(); ++i)
std::cerr << " " << cloud->points[i].x << " "
<< cloud->points[i].y << " "
<< cloud->points[i].z << std::endl;
// Create a set of planar coefficients with X=Y=0,Z=1
pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients());
coefficients->values.resize(4);
coefficients->values[0] = 1;
coefficients->values[1] = 0;
coefficients->values[2] = 0;
coefficients->values[3] = 0;
// Create the filtering object
pcl::ProjectInliers<pcl::PointXYZ> proj;
proj.setModelType(pcl::SACMODEL_PLANE);
proj.setInputCloud(cloud);
proj.setModelCoefficients(coefficients);
proj.filter(*cloud_projected);
std::cerr << "Cloud after projection: " << std::endl;
for (size_t i = 0; i < cloud_projected->points.size(); ++i)
std::cerr << " " << cloud_projected->points[i].x << " "
<< cloud_projected->points[i].y << " "
<< cloud_projected->points[i].z << std::endl;
getchar();
return (0);
}
Make a slight modification to solve the crash problem when running the program.
The method to solve the program crash: add #include<stdio.h> to the header file and add getchar() before return;
Program running effect:

Project source download link: link: https://pan.baidu.com/s/1U7lmM_zGujZJ8_pWm1OpdA
Extraction code: y9dq
Among them, the PCL version is 1.9.1.
Reference blog post: 1,pcl point projected to a plane
This code is that it is true that it is known to specify the designated plane to calculate the coordinates of the point after the projection. First define a projection filter, set the input point clou...
3D point projection to 2D screen, matrix calculation background algorithm Complete code pending upgrade background Recently Optimized the 3D Jitter Jitter of Vibe Output. The 3D point is needed to pro...
background: pcl official tutorial: http://www.pointclouds.org/documentation/tutorials/planar_segmentation.php#planar-segmentation Note: The segmentation algorithm is not in the true sense, because it ...
pcl- 3D point cloud library Some of the property values pcl :: PointCloud width(int) two meanings: it can specify the total number of points in the cloud for unorganized point cloud datasets; it can...
Introduction This blog post mainly introduces how to project point cloud to parametric model (for example: plane, sphere, etc.). The parametric model is given by a set of coefficients, such as a pl...
Environmental installation Can refer to my other article: Point Cloud Learning Notes 3 - Point Cloud Library (PCL) Installation and Test Tutorial Point cloud data Code Renderings refer to...
Recently, I have been doing a project, you need to take a point cloud to any plane, try the projected code of the online PCL. Using a flat method vector never get the correct result, so use CGAL imple...
Introduction to the segmentation module and class in PCL: Point cloud segmentation experiment program: Source code: // RANSAC.cpp: Defines the entry point for the console applicat...
PCL point cloud model into the plane of division --- Suitable working principle PCL core code implementation Reference material Suitable Cloud point suitable for large planar division exists, such as ...