PCL RANSAC点云配准
生活随笔
收集整理的這篇文章主要介紹了
PCL RANSAC点云配准
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 一、概述
- 二、代碼
- 三、結果
一、概述
??PCL中RANSAC點云配準的簡單使用案例。
二、代碼
alignment_prerejective.cpp
#include <Eigen/Core>#include <pcl/point_types.h> #include <pcl/point_cloud.h> #include <pcl/common/time.h> #include <pcl/console/print.h> #include <pcl/features/normal_3d_omp.h> #include <pcl/features/fpfh_omp.h> #include <pcl/filters/filter.h> #include <pcl/filters/voxel_grid.h> #include <pcl/io/pcd_io.h> #include <pcl/registration/icp.h> #include <pcl/registration/sample_consensus_prerejective.h> #include <pcl/visualization/pcl_visualizer.h>// Types typedef pcl::PointNormal PointNT; typedef pcl::PointCloud<PointNT> PointCloudT; typedef pcl::FPFHSignature33 FeatureT; typedef pcl::FPFHEstimationOMP<PointNT,PointNT,FeatureT> FeatureEstimationT; typedef pcl::PointCloud<FeatureT> FeatureCloudT; typedef pcl::visualization::PointCloudColorHandlerCustom<PointNT> ColorHandlerT;// Align a rigid object to a scene with clutter and occlusions int main (int argc, char **argv) {// Point cloudsPointCloudT::Ptr object (new PointCloudT);PointCloudT::Ptr object_aligned (new PointCloudT);PointCloudT::Ptr scene (new PointCloudT);FeatureCloudT::Ptr object_features (new FeatureCloudT);FeatureCloudT::Ptr scene_features (new FeatureCloudT);// Load object and scenepcl::console::print_highlight ("Loading point clouds...\n");if (pcl::io::loadPCDFile<PointNT>("chef.pcd", *object) < 0 ||pcl::io::loadPCDFile<PointNT>("rs1.pcd", *scene) < 0){pcl::console::print_error ("Error loading object/scene file!\n");return (1);}// Downsamplepcl::console::print_highlight ("Downsampling...\n");pcl::VoxelGrid<PointNT> grid;const float leaf = 0.005f;grid.setLeafSize (leaf, leaf, leaf);grid.setInputCloud (object);grid.filter (*object);grid.setInputCloud (scene);grid.filter (*scene);// Estimate normals for scenepcl::console::print_highlight ("Estimating scene normals...\n");pcl::NormalEstimationOMP<PointNT,PointNT> nest;nest.setRadiusSearch (0.01);nest.setInputCloud (scene);nest.compute (*scene);// Estimate featurespcl::console::print_highlight ("Estimating features...\n");FeatureEstimationT fest;fest.setRadiusSearch (0.025);fest.setInputCloud (object);fest.setInputNormals (object);fest.compute (*object_features);fest.setInputCloud (scene);fest.setInputNormals (scene);fest.compute (*scene_features);// Perform alignmentpcl::console::print_highlight ("Starting alignment...\n");pcl::SampleConsensusPrerejective<PointNT,PointNT,FeatureT> align;align.setInputSource (object);align.setSourceFeatures (object_features);align.setInputTarget (scene);align.setTargetFeatures (scene_features);align.setMaximumIterations (50000); // Number of RANSAC iterationsalign.setNumberOfSamples (3); // Number of points to sample for generating/prerejecting a posealign.setCorrespondenceRandomness (5); // Number of nearest features to usealign.setSimilarityThreshold (0.9f); // Polygonal edge length similarity thresholdalign.setMaxCorrespondenceDistance (2.5f * leaf); // Inlier thresholdalign.setInlierFraction (0.25f); // Required inlier fraction for accepting a pose hypothesis{pcl::ScopeTime t("Alignment");align.align (*object_aligned);}if (align.hasConverged ()){// Print resultsprintf ("\n");Eigen::Matrix4f transformation = align.getFinalTransformation ();pcl::console::print_info (" | %6.3f %6.3f %6.3f | \n", transformation (0,0), transformation (0,1), transformation (0,2));pcl::console::print_info ("R = | %6.3f %6.3f %6.3f | \n", transformation (1,0), transformation (1,1), transformation (1,2));pcl::console::print_info (" | %6.3f %6.3f %6.3f | \n", transformation (2,0), transformation (2,1), transformation (2,2));pcl::console::print_info ("\n");pcl::console::print_info ("t = < %0.3f, %0.3f, %0.3f >\n", transformation (0,3), transformation (1,3), transformation (2,3));pcl::console::print_info ("\n");pcl::console::print_info ("Inliers: %i/%i\n", align.getInliers ().size (), object->size ());// Show alignmentpcl::visualization::PCLVisualizer visu("Alignment");visu.addPointCloud (scene, ColorHandlerT (scene, 0.0, 255.0, 0.0), "scene");visu.addPointCloud (object_aligned, ColorHandlerT (object_aligned, 0.0, 0.0, 255.0), "object_aligned");visu.spin ();}else{pcl::console::print_error ("Alignment failed!\n");return (1);}return (0); }三、結果
> Loading point clouds... Failed to find match for field 'curvature'. Failed to find match for field 'normal_x'. Failed to find match for field 'normal_y'. Failed to find match for field 'normal_z'. Failed to find match for field 'curvature'. > Downsampling... > Estimating scene normals... > Estimating features... > Starting alignment... Alignment took 986.837ms.| 0.871 0.194 0.451 | R = | -0.479 0.135 0.867 || 0.107 -0.972 0.210 |t = < 0.238, 0.657, 0.730 >Inliers: 1195/3432總結
以上是生活随笔為你收集整理的PCL RANSAC点云配准的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果cms模板 短视8.1旗舰版
- 下一篇: 项目管理第九章项目资源管理