自动驾驶之多传感器融合实践(3)-------基于图像检测框对点云聚类

通过YOLO检测得到目标的检测框后,这些区域就可以作为ROI将包含在各roi内的点云分组聚类出来,从而通过点云得到目标的准确位置。
代码解析:
1.boundingbox数据结构:

struct BoundingBox { // bounding box around a classified object (contains both 2D and 3D data)

    int boxID; // unique identifier for this bounding box
    int trackID; // unique identifier for the track to which this bounding box belongs

    cv::Rect roi; // 2D region-of-interest in image coordinates
    int classID; // ID based on class file provided to YOLO framework
    double confidence; // classification trust

    std::vector<LidarPoint> lidarPoints; // Lidar 3D points which project into 2D image roi
    std::vector<cv::KeyPoint> keypoints; // keypoints enclosed by 2D roi
    std::vector<cv::DMatch> kptMatches; // keypoint matches enclosed by 2D roi
};

2.调整boundingbox大小,减少两个重叠区域包含同一部分点云的情况
在这里插入图片描述
发现框图往往会比实际物体大一些,这样的话,会把一些不属于目标物体的点,聚类到该物体上了。所以往往会在原来框图的基础上缩小一定比例,然后将投影在缩小之后的小框图上的点保留,下面分别是缩小10%,25%的结果。

vector<vector<BoundingBox>::iterator> enclosingBoxes; // pointers to all bounding boxes which enclose the current Lidar point
for (vector<BoundingBox>::iterator it2 = boundingBoxes.begin(); it2 != boundingBoxes.end(); ++it2)
{
    // shrink current bounding box slightly to avoid having too many outlier points around the edges
    cv::Rect smallerBox;
    smallerBox.x = (*it2).roi.x + shrinkFactor * (*it2).roi.width / 2.0;
    smallerBox.y = (*it2).roi.y + shrinkFactor * (*it2).roi.height / 2.0;
    smallerBox.width = (*it2).roi.width * (1 - shrinkFactor);
    smallerBox.height = (*it2).roi.height * (1 - shrinkFactor);

因子“ shrinkFactor”,该因子表示以[%]为单位的大小调整量,从原始边界框创建了一个较小的框。在实践中,应使用5-10%的适当设置,以避免丢弃过多的数据。

3.避免错误分组
有时候检测框会包含不属于本车辆的点云,在这里主要通过循环检测框中点,只保留那些仅存在与一个检测框中的点。

 if (smallerBox.contains(pt))  
            {
              
                enclosingBoxes.push_back(it2); //remove overlapping points
            }
        } // eof loop over all bounding boxes

        if (enclosingBoxes.size() == 1){
            enclosingBoxes[0]->lidarPoints.push_back(*it1); //collect the point contained for every rectangle
        }

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
k-means聚类是一种应用于点数据的聚类算法,可以通过将点数据划分为不同的簇来实现数据的分类和分割。PCL(点库)是一个用于点处理的开源库,其中包含了用于点k-means聚类的Python模块。 点k-means聚类的过程如下:首先,选取合适数量(k)的初始聚类中心点。然后,将每个点与聚类中心点进行距离计算,并将其分配给离其最近的中心点所对应的聚类。接着,根据每个聚类中的点重新计算其聚类中心点。重复以上两个步骤,直到聚类中心点的位置不再变化或者达到预定的迭代次数为止。 使用PCL库的Python模块,在进行点k-means聚类时,首先需要导入相关的模块和数据。然后,通过调用PCL库中的聚类算法函数,传入点数据和所需的聚类数量k。接着,可以设置聚类算法的参数,如迭代次数、收敛阈值等。最后,调用聚类算法函数来执行点k-means聚类,并获取聚类的结果。 在得到点k-means聚类的结果后,可以对每个聚类进行进一步的操作,如可视化显示每个聚类的点数据、计算每个聚类的质心或其他统计量等。此外,可以根据具体的需求调整聚类算法的参数,以获得更好的聚类效果。 总而言之,点k-means聚类是一种有效的点数据处理方法,可通过使用PCL库的Python模块来实现。该方法可以对点数据进行分类和分割,从而对点数据进行更深入的分析和应用。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值