PCL點雲配準:ICP使用
阿新 • • 發佈:2021-01-16
目錄
ICP流程分為4個主要步驟
1、對原始點雲資料進行取樣,得到初始的點雲集合;
2、確定初始對應點集,模板點集在待匹配點集的位置,對結果有至關重要的影響;
3、去除錯誤對應點對,通過最小二乘法迭代獲取正確的匹配點;
4、座標變換求解,得到旋轉矩陣R和平移向量t;
完成高精度的變換矩陣估計;
使用一點感受
初始點集合,非常非常非常之重要,對最後結果有至關重要的作用;
迭代次數多了之後,或者點雲大了之後,運算速度確實慢;
是一種精度比較高的變換矩陣估計,但是精度多高還得結合實際情況,如果需要精度特別高的話還得測試;
實現程式碼
#include <iostream> #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include <pcl/registration/icp.h> int main(int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in(new pcl::PointCloud<pcl::PointXYZ>(5, 1)); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out(new pcl::PointCloud<pcl::PointXYZ>); // Fill in the CloudIn data for (auto& point : *cloud_in) { point.x = 1024 * rand() / (RAND_MAX + 1.0f); point.y = 1024 * rand() / (RAND_MAX + 1.0f); point.z = 1024 * rand() / (RAND_MAX + 1.0f); } std::cout << "Saved " << cloud_in->size() << " data points to input:" << std::endl; for (auto& point : *cloud_in) std::cout << point << std::endl; *cloud_out = *cloud_in; std::cout << "size:" << cloud_out->size() << std::endl; for (auto& point : *cloud_out) point.x += 0.7f; std::cout << "Transformed " << cloud_in->size() << " data points:" << std::endl; for (auto& point : *cloud_out) std::cout << point << std::endl; pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp; icp.setInputSource(cloud_in); icp.setInputTarget(cloud_out); pcl::PointCloud<pcl::PointXYZ> Final; icp.align(Final); std::cout << "has converged:" << icp.hasConverged() << " score: " << icp.getFitnessScore() << std::endl; std::cout << icp.getFinalTransformation() << std::endl; return (0); }
《點雲庫PCL從入門到精通》