• PCL 投影点云


    投影到XOY平面上

    #include <iostream>
    #include <pcl/io/pcd_io.h>
    #include <pcl/point_types.h>
    #include <pcl/point_cloud.h>
    #include <pcl/ModelCoefficients.h>
    #include <pcl/filters/project_inliers.h>
    #include <pcl/visualization/pcl_visualizer.h>
    
    using namespace std;
    using namespace pcl;
    
    void visualize(PointCloud<PointXYZ>::Ptr source, PointCloud<PointXYZ>::Ptr target)
    {
    	visualization::PCLVisualizer viewer("Point Cloud Viewer");
    
    	// 创建两个显示窗口
    	int v1, v2;
    	viewer.createViewPort(0, 0.0, 0.5, 1.0, v1);
    	viewer.createViewPort(0.5, 0.0, 1.0, 1.0, v2);
    	// 设置背景颜色
    	viewer.setBackgroundColor(255, 255, 255, v1);
    	viewer.setBackgroundColor(255, 255, 255, v2);
    
    	// 给点云添加颜色
    	visualization::PointCloudColorHandlerCustom<PointXYZ> source_color(source, 0, 0, 255);  // blue
    
    	visualization::PointCloudColorHandlerCustom<PointXYZ> target_color(target, 255, 0, 0);  // red
    
    
    	// 添加点云到显示窗口
    	viewer.addPointCloud(source, source_color, "source cloud", v1);
    	viewer.addPointCloud(target, target_color, "target cloud", v2);
    
    
    	while (!viewer.wasStopped())
    	{
    		viewer.spinOnce(100);
    		boost::this_thread::sleep(boost::posix_time::microseconds(100000));
    	}
    
    }
    
    
    int main(int argc, char** argv)
    {
    	PointCloud<PointXYZ>::Ptr cloud(new pcl::PointCloud<PointXYZ>);
    	PointCloud<PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<PointXYZ>);
    
    	io::loadPCDFile("D:\\Data\\rabbit.pcd", *cloud);
    	// 输出滤波前点的个数
    	cout << "滤波前有:" << cloud->points.size() << "个点" << endl;
    
    	// 设置模型参数的系数
    	ModelCoefficients::Ptr coefficients(new ModelCoefficients());
    	coefficients->values.resize(4);
    	coefficients->values[0] = 0;
    	coefficients->values[1] = 0;
    	coefficients->values[2] = 1.0;
    	coefficients->values[3] = 0;
    
    	// 实例化滤波器对象
    	ProjectInliers<PointXYZ> proj;
    	proj.setModelType(SACMODEL_PLANE);
    	proj.setInputCloud(cloud);
    	proj.setModelCoefficients(coefficients);
    	proj.filter(*filtered_cloud);
    
    	cout << "滤波后有:" << filtered_cloud->points.size() << "个点" << endl;
    
    	visualize(cloud, filtered_cloud);
    
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73

    可以投影的其它模型

    可以使用的投影模型如下:
    平面模型:SACMODEL_PLANE
    线模型:SACMODEL_LINE
    平面上的二维圆:SACMODEL_CIRCLE2D
    平面上的三维圆:SACMODEL_CIRCLE3D
    球体模型:SACMODEL_SPHERE
    圆柱模型:SACMODEL_CYLINDER
    圆锥模型:SACMODEL_CONE
    圆环模型:SACMODEL_TORUS
    平行于给定轴的一种线模型:SACMODEL_PARALLEL_LINE
    垂直于指定轴的平面模型:SACMODEL_PERPENDICULAR_PLANE
    三维棒分割模型:SACMODEL_STICK

  • 相关阅读:
    Taurus.MVC 性能压力测试(ap 压测 和 linux 下wrk 压测):.NET Core 版本
    Error: error:0308010C:digital envelope routines::unsupported
    java计算机毕业设计高校多媒体设备报修管理系统MyBatis+系统+LW文档+源码+调试部署
    chatGPT API中参数temperature的含义是什么
    linux查看ip
    深入浅出讲解Spring IOC和DI的区别
    CompletableFuture
    三道有趣的算法题
    Linux中防火墙的简单使用方法
    学生个人网页设计作品:旅游网页设计与实现——成都旅游网站4个页HTML+CSS web前端网页设计期末课程大作业 学生DW静态网页设计 学生个人网页设计作品
  • 原文地址:https://blog.csdn.net/u011489887/article/details/125548393