PCL:合并两个点云

歪瑞easy,看一眼就会。

1 非指针形式

#include <pcl/io/pcd_io.h>

using namespace std;

typedef pcl::PointXYZRGB PointT;
typedef pcl::PointCloud<PointT> PointCloudT;

int main()
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论
以下是使用PCL库将两个pcd点云合并的示例代码: ```cpp #include <iostream> #include <pcl/point_types.h> #include <pcl/io/pcd_io.h> #include <pcl/registration/icp.h> int main(int argc, char** argv) { // 读取第一个点云 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in(new pcl::PointCloud<pcl::PointXYZ>); if (pcl::io::loadPCDFile<pcl::PointXYZ>("cloud_in.pcd", *cloud_in) == -1) { PCL_ERROR("Couldn't read file cloud_in.pcd"); return (-1); } // 读取第二个点云 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out(new pcl::PointCloud<pcl::PointXYZ>); if (pcl::io::loadPCDFile<pcl::PointXYZ>("cloud_out.pcd", *cloud_out) == -1) { PCL_ERROR("Couldn't read file cloud_out.pcd"); return (-1); } // 定义ICP对象 pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp; icp.setMaximumIterations(50); // 设置最大迭代次数 icp.setInputSource(cloud_in); // 设置输入点云 icp.setInputTarget(cloud_out); // 设置目标点云 // 进行配准 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_merged(new pcl::PointCloud<pcl::PointXYZ>); icp.align(*cloud_merged); // 输出配准结果 if (icp.hasConverged()) { std::cout << "ICP has converged, score: " << icp.getFitnessScore() << std::endl; std::cout << "Transformation matrix:" << std::endl << icp.getFinalTransformation() << std::endl; } else { std::cout << "ICP has not converged" << std::endl; return (-1); } // 保存合并后的点云 pcl::io::savePCDFileASCII("cloud_merged.pcd", *cloud_merged); return (0); } ``` 这段代码使用了迭代最近点(ICP)算法进行点云配准,并将两个点云合并为一个。其中,`cloud_in.pcd`和`cloud_out.pcd`是两个合并点云文件,`cloud_merged.pcd`是合并后的点云文件。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孙 悟 空

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值