PCL 1.8.1 ICP 点到点配准算法代码示例:斯坦福雕像配准
#include
int main(int argc, char** argv) { // 读取点云数据 pcl::PointCloudpcl::PointXYZ::Ptr source_cloud(new pcl::PointCloudpcl::PointXYZ); pcl::PointCloudpcl::PointXYZ::Ptr target_cloud(new pcl::PointCloudpcl::PointXYZ); if (pcl::io::loadPCDFilepcl::PointXYZ("D:\点云文件\点云数据\规则点云\斯坦福\雕像1.pcd", *source_cloud) == -1) { PCL_ERROR("Couldn't read file source_cloud.pcd\n"); return (-1); } if (pcl::io::loadPCDFilepcl::PointXYZ("D:\点云文件\点云数据\规则点云\斯坦福\雕像2.pcd", *target_cloud) == -1) { PCL_ERROR("Couldn't read file target_cloud.pcd\n"); return (-1); }
// 定义ICP对象
pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
icp.setInputSource(source_cloud); // 设置源点云
icp.setInputTarget(target_cloud); // 设置目标点云
// 设置ICP参数
icp.setMaxCorrespondenceDistance(0.05); // 最大对应点距离
icp.setMaximumIterations(100); // 最大迭代次数
icp.setTransformationEpsilon(1e-8); // 变换矩阵收敛判断阈值
icp.setEuclideanFitnessEpsilon(1e-8); // 变换矩阵收敛后的匹配误差阈值
// 执行ICP配准
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_transformed(new pcl::PointCloud<pcl::PointXYZ>);
icp.align(*cloud_transformed);
// 输出配准结果
std::cout << "has converged:" << icp.hasConverged() << " score: " << icp.getFitnessScore() << std::endl;
std::cout << icp.getFinalTransformation() << std::endl;
// 保存配准后的点云数据
pcl::io::savePCDFileASCII("D:\DIANYUNWENJIANJIA\icp_pcd.pcd", *cloud_transformed);
return (0);
}
原文地址: https://www.cveoy.top/t/topic/oZ1t 著作权归作者所有。请勿转载和采集!