PCL正态分布变换(Normal Distributions Transform)进行点云配准
2018-04-04 16:32
302 查看
直接记录代码
void NormTran::run() { readfile("bunny_0.asc", "bunny_1.asc");//加载目标点云数据 //滤波 pcl::ApproximateVoxelGrid<pcl::PointXYZ> approximate_voxel_filter; approximate_voxel_filter.setLeafSize(0.01, 0.01, 0.01); approximate_voxel_filter.setInputCloud(cloud_Source); approximate_voxel_filter.filter(*filtered_cloud_Source); std::cout << "Filtered cloud contains " << filtered_cloud_Source->size() << std::endl; // //初始化NDT对象 pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> ndt; //根据输入数据的尺寸设置相关参数 ndt.setTransformationEpsilon(0.0001);//为终止条件设置最小转换差异 ndt.setStepSize(0.1); //为more-thuente线搜索设置最大步长 ndt.setResolution(0.01); //设置NDT网格网格结构的分辨率(voxelgridcovariance) ndt.setMaximumIterations(100); ndt.setInputSource(filtered_cloud_Source);//源点云 ndt.setInputTarget(cloud_Target);//目标点云 // 设置使用机器人测距法得到的粗略初始变换矩阵结果 Eigen::AngleAxisf init_rotation(0.6931, Eigen::Vector3f::UnitZ()); Eigen::Translation3f init_translation(1.79387, 0.72047, 0); Eigen::Matrix4f init_guess = (init_translation * init_rotation).matrix(); // 计算需要的刚体变换以便将输入的源点云匹配到目标点云 pcl::PointCloud<pcl::PointXYZ>::Ptr output_cloud(new pcl::PointCloud<pcl::PointXYZ>); ndt.align(*output_cloud, init_guess); //这个地方的output_cloud不能作为最终的源点云变换,因为上面对点云进行了滤波处理 std::cout << "Normal Distributions Transform has converged:" << ndt.hasConverged() << bb51 " score: " << ndt.getFitnessScore() << std::endl; pcl::transformPointCloud(*cloud_Source,*output_cloud,ndt.getFinalTransformation()); // 初始化点云可视化对象 boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer_final(new pcl::visualization::PCLVisualizer("3D Viewer")); viewer_final->setBackgroundColor(0, 0, 0); //设置背景颜色为黑色 // 对目标点云着色可视化 (red). pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> target_color(cloud_Target, 255, 0, 0); viewer_final->addPointCloud<pcl::PointXYZ>(cloud_Target, target_color, "target cloud"); viewer_final->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "target cloud"); //对源点云着色可视化(blue) pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> source_color(cloud_Source, 0, 0, 255); viewer_final->addPointCloud(cloud_Source, source_color, "source_cloud"); viewer_final->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "source cloud"); //创建配准后的显示 int v2 = 1; viewer_final->createViewPort(0.5, 0, 1, 1, v2); viewer_final->createViewPortCamera(v2); viewer_final->setBackgroundColor(0, 0, 0, v2); viewer_final->setCameraPosition( 0, 0, 0, 0, 0, -1, 0, 0, 0, v2); // 对转换后的源点云着色 (green)可视化. pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> output_color(output_cloud, 0, 255, 0); viewer_final->addPointCloud(cloud_Source, source_color, "source_cloud1",v2); viewer_final->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "source cloud1",v2); viewer_final->addPointCloud<pcl::PointXYZ>(output_cloud, output_color, "output cloud",v2); viewer_final->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "output cloud",v2); // 启动可视化 viewer_final->addCoordinateSystem(1.0); //显示XYZ指示轴 viewer_final->initCameraParameters(); //初始化摄像头参数 // 等待直到可视化窗口关闭 while (!viewer_final->wasStopped()) { viewer_final->spinOnce(100); boost::this_thread::sleep(boost::posix_time::microseconds(100000)); } }
相关文章推荐
- 使用正态分布变换(Normal Distributions Transform)进行点云配准
- 使用正态分布变换进行配准
- PCL点云库:对点云进行变换(Using a matrix to transform a point cloud)
- [置顶] 无人驾驶汽车系统入门(十三)——正态分布变换(NDT)配准与无人车定位
- CSS3中的transform属性进行2D和3D变换的基本用法
- PCL学习笔记--利用矩阵对点云进行刚体变换
- NDT(Normal Distributions Transform)算法原理与公式推导
- 傅立叶变换、拉普拉斯变换、Z变换的联系?为什么要进行这些变换。研究的都是什么?
- 使用ActiveReports for .net 进行报表开发--交叉变换背景
- 介绍css 的3D 变换(3D transform)
- CSS3 -webkit-transform(元素变换)
- 【C#/WPF】Image图片的Transform变换:平移、缩放、旋转
- 理解SVG坐标系统和变换: transform属性
- ios-day02-03(使用transform对按钮进行平移、缩放、旋转)
- 视频编码中为什么须要进行变换编码?
- Android 里面使用Matrix进行简单地变换
- unity3d InverseTransformPoint 相反变换位置
- Unity之路(四):变换组件Transform
- 如何根据坐标架进行点的坐标变换
- transform 容器元素变换函数