一、基于PCL的点云数据初校验与处理——3D点云处理系列

点云预处理

在点云正式处理之前,主要对点云数据进行预处理的一些工作,比如NAN去除、特征值异常检测、自定义条件异常检测等等。

1.NAN去除

读取点云

    //创建点云指针,最原始点云数据
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_source(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::io::loadPCDFile("C:/pclpoint/1012/Cloud0.pcd", *cloud_source);
    //去除NAN点
    std::vector<int> indices_src; //保存去除的点的索引
    pcl::removeNaNFromPointCloud(*cloud_source, *cloud_source, indices_src);

2.特征值检测

void EigenvalueDetection(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud) {
    // 计算点云的特征值
    pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
    pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normal_estimation;
    pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
    normal_estimation.setInputCloud(cloud);
    normal_estimation.setSearchMethod(tree);
    normal_estimation.setKSearch(10);
    normal_estimation.compute(*normals);
    // 定义异常标准并标记异常点
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr colored_cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
    for (int i = 0; i < cloud->size(); ++i) {
        float curvature = normals->at(i).curvature;
        // 根据定义的异常标准判断是否为异常点
        if (curvature > 0.2) {
            pcl::PointXYZRGB colored_point;
            colored_point.x = cloud->at(i).x;
            colored_point.y = cloud->at(i).y;
            colored_point.z = cloud->at(i).z;
            colored_point.r = 255;  // 标记异常点的颜色为红色
            colored_point.g = 0;
            colored_point.b = 0;
            colored_cloud->push_back(colored_point);
        }
    }
}

2.自定义条件异常检测

//自定义异常值筛选
void CustomValueDetection(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_source) {
    pcl::PointIndices::Ptr inliers1(new pcl::PointIndices());
    pcl::ExtractIndices<pcl::PointXYZ> extract;//提取符合要求的
    for (int i = 0; i < cloud_source->size(); i++) {
        if (fabs(cloud_source->points[i].x) < 0.1) {**//自定义的条件**
            inliers1->indices.push_back(i);
            cout << "cloud_source:" << cloud_source->points[i].x << endl;
        }
    }
    extract.setInputCloud(cloud_source);
    extract.setIndices(inliers1);
    extract.setNegative(true);
    extract.filter(*cloud_source);
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

定位算法工程师

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

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

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

打赏作者

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

抵扣说明:

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

余额充值