PCL 常用操作

复制点云

  1. 添加点的方式到新的点云
    cloud->push_back(point);
    
  2. 通过索引添加
    template <typename PointT> 
    void copyPoints(const pcl::PointCloud<PointT> &cloud_in, const std::vector<int> &indices, pcl::PointCloud<PointT> &cloud_out)
    {
    	if (indices.size() == cloud_in.points.size())
    	{
    		cloud_out = cloud_in;
    		return;
    	}
    	cloud_out.points.resize(indices.size());
    	cloud_out.header = cloud_in.header;
    	cloud_out.width = static_cast<uint32_t>(indices.size());
    	cloud_out.height = 1;
    	cloud_out.is_dense = cloud_in.is_dense;
    	cloud_out.sensor_orientation_ = cloud_in.sensor_orientation_;
    	cloud_out.sensor_origin_ = cloud_in.sensor_origin_;
    	for (size_t i = 0; i < indices.size(); ++i)
    	{
    		cloud_out[i] = cloud_in[indices[i]];
    	}
    }
    
  3. 函数调用
    这种方式还可用于点云格式转换,如source为XYZI,result为XYZ.
    pcl::copyPointCloud(*source, *result);
    
  4. 两个点云叠加在一块
    *cloud_c = *cloud_a + *cloud_b;
    

用时对比

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/shadowpoints.h>
#include <pcl/features/normal_3d.h>
#include <pcl/common/common.h>
#include <mutex>
#include <time.h>
#include <omp.h>

using namespace std;

int main()
{
	pcl::PointCloud<pcl::PointXYZ>::Ptr source(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr t1(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr t2(new pcl::PointCloud<pcl::PointXYZ>);
	int point_num = 20000000;
	for (int i=0;i<point_num;i++)
	{
		pcl::PointXYZ point;
		point.x = rand();
		point.y = rand();
		point.z = rand();
		source->points.push_back(point);
	}

	clock_t start = clock();
	pcl::copyPointCloud(*source,*t1);
	clock_t end = clock();
	cout << end - start << endl;


	mutex push_lock;
//#pragma omp parallel for 
	for (int i = 0; i < point_num; i++)
	{
		push_lock.lock();
		t2->points.push_back(source->points[i]);
		push_lock.unlock();
		Sleep(1);
	}

	clock_t end2 = clock();
	cout << end2 - end << endl;

	return 0;
}

在这里插入图片描述
pcl::copyPointCloud()方法更快。

pcl学习资料:https://zhuanlan.zhihu.com/p/268524083
pcl常用数据集: https://blog.csdn.net/qq_27816785/article/details/124856990

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

AICVer

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

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

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

打赏作者

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

抵扣说明:

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

余额充值