0

我正在尝试使用 PCL 示例代码(欧几里得集群提取https ://pcl.readthedocs.io/projects/tutorials/en/latest/cluster_extraction.html#cluster-extraction )来获取集群 PCL。

我使用BuildRoot构建代码并在 RK3568 板上运行演示,但无法执行结果。在 Ubuntu 中运行代码可以得到结果。我用gdb调试代码,调试信息如下:</p>

(gdb) bt
[2021-11-19 17:27:18]  #0  0x0000007ff3aa0270 in flann::DistanceIndex<float>::operator<(flann::DistanceIndex<float> const&) const@plt () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:18]  #1  0x0000007ff3cee72c in __gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > > std::__unguarded_partition_pivot<__gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, __gnu_cxx::__ops::_Iter_less_iter>(__gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, __gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, __gnu_cxx::__ops::_Iter_less_iter) () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:18]  #2  0x0000007ff3d0849c in ?? () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:18]  #3  0x0000007ff3d084b0 in ?? () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:18]  #4  0x0000007ff3d08500 in ?? () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:18]  #5  0x0000007ff3d223c8 in ?? () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:18]  #6  0x0000007fee166228 in GOMP_parallel () from /lib/libgomp.so.1
[2021-11-19 17:27:18]  #7  0x0000007ff3d2ca7c in int pcl::detail::radius_search<int, flann::Index<flann::L2_Simple<float> > const, flann::Matrix<float> const, std::vector<int, std::allocator<int> >, std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >, flann::SearchParams const, true>(flann::Index<flann::L2_Simple<float> > const&, flann::Matrix<float> const&, std::vector<int, std::allocator<int> >&, std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >&, float, flann::SearchParams const&) ()
[2021-11-19 17:27:18]     from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:18]  #8  0x0000007ff3d2cef0 in pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::radiusSearch(pcl::PointXYZ const&, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:18]  #9  0x0000007ff3aba0ac in void pcl::extractEuclideanClusters<pcl::PointXYZ>(pcl::PointCloud<pcl::PointXYZ> const&, std::vector<int, std::allocator<int> > const&, pcl::search::Search<pcl::PointXYZ>::Ptr const&, float, std::vector<pcl::PointIndices, std::allocator<pcl::PointIndices> >&, unsigned int, unsigned int) () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:18]  #10 0x0000007ff3aba450 in pcl::EuclideanClusterExtraction<pcl::PointXYZ>::extract(std::vector<pcl::PointIndices, std::allocator<pcl::PointIndices> >&) () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:18]  #11 0x0000007ff6b9242c in soa::FusionStrategyUnknownObject::GetPclCluster (this=0x7fe883ad30, trans_msg=...)
[2021-11-19 17:27:18]      at /work/jason/demo/soa/od_fusion/src/strategy/strategy_unknown_object/src/fusion_strategy_unknown_object.cc:304
[2021-11-19 17:27:18]  #12 0x0000007ff6b915a4 in soa::FusionStrategyUnknownObject::Process (this=0x7fe883ad30, disparity_info=..., od_boxes_info=...)
[2021-11-19 17:27:18]      at /work/jason/demo/soa/od_fusion/src/strategy/strategy_unknown_object/src/fusion_strategy_unknown_object.cc:148
[2021-11-19 17:27:18]  #13 0x0000007ff6b7ba0c in soa::OdFusionMgrImpl::<lambda()>::operator()(void) const (__closure=0x7fe8053130) at /work/jason/demo/soa/od_fusion/src/od_fusion_mgr.cc:282
[2021-11-19 17:27:18]  #14 0x0000007ff6b7cd44 in std::_Function_handler<void(), soa::OdFusionMgrImpl::Init()::<lambda()> >::_M_invoke(const std::_Any_data &) (__functor=...)
[2021-11-19 17:27:18]      at /sdk/buildroot/output/rockchip_rk3568/host/aarch64-buildroot-linux-gnu/include/c++/9.3.0/bits/std_function.h:300
[2021-11-19 17:27:18]  #15 0x0000007ff5262e74 in std::function<void ()>::operator()() const () from /lib/librequest_thread.so
[2021-11-19 17:27:18]  #16 0x0000007ff525a1d4 in soa::Task::Hanlder() () from /lib/librequest_thread.so
[2021-11-19 17:27:18]  #17 0x0000007ff525a28c in soa::RequestThread::Routine() () from /lib/librequest_thread.so
[2021-11-19 17:27:18]  #18 0x0000007ff52af8ac in void std::__invoke_impl<void, void (soa::RequestThread::*)(), soa::RequestThread*>(std::__invoke_memfun_deref, void (soa::RequestThread::*&&)(), soa::RequestThread*&&) ()
[2021-11-19 17:27:18]     from /lib/librequest_thread.so
[2021-11-19 17:27:18]  #19 0x0000007ff52af76c in std::__invoke_result<void (soa::RequestThread::*)(), soa::RequestThread*>::type std::__invoke<void (soa::RequestThread::*)(), soa::RequestThread*>(void (soa::RequestThread::*&&)(), soa::RequestThread*&&) () from /lib/librequest_thread.so
[2021-11-19 17:27:18]  #20 0x0000007ff52af3b4 in void std::thread::_Invoker<std::tuple<void (soa::RequestThread::*)(), soa::RequestThread*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) ()
[2021-11-19 17:27:18]     from /lib/librequest_thread.so
[2021-11-19 17:27:18]  #21 0x0000007ff52aed44 in std::thread::_Invoker<std::tuple<void (soa::RequestThread::*)(), soa::RequestThread*> >::operator()() () from /lib/librequest_thread.so
[2021-11-19 17:27:18]  #22 0x0000007ff52ab0a0 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (soa::RequestThread::*)(), soa::RequestThread*> > >::_M_run() () from /lib/librequest_thread.so
[2021-11-19 17:27:18]  #23 0x0000007ff42df3b0 in ?? () from /lib/libstdc++.so.6
[2021-11-19 17:27:18]  #24 0x0000007ff71846d0 in start_thread () from /lib/libpthread.so.0
[2021-11-19 17:27:18]  #25 0x0000007ff40a76cc in ?? () from /lib/libc.so.6
[2021-11-19 17:27:18]  (gdb) s s n
[2021-11-19 17:27:28]  Single stepping until exit from function _ZNK5flann13DistanceIndexIfEltERKS1_@plt,
[2021-11-19 17:27:28]  which has no line number information.
[2021-11-19 17:27:28]  0x0000007ff3cee658 in flann::DistanceIndex<float>::operator<(flann::DistanceIndex<float> const&) const () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:28]  (gdb) n
[2021-11-19 17:27:33]  Single stepping until exit from function _ZNK5flann13DistanceIndexIfEltERKS1_,
[2021-11-19 17:27:33]  which has no line number information.
[2021-11-19 17:27:33]  0x0000007ff3cee72c in __gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > > std::__unguarded_partition_pivot<__gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, __gnu_cxx::__ops::_Iter_less_iter>(__gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, __gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, __gnu_cxx::__ops::_Iter_less_iter) () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:27:33]  (gdb) n
[2021-11-19 17:27:34]  Single stepping until exit from function _ZSt27__unguarded_partition_pivotIN9__gnu_cxx17__normal_iteratorIPN5flann13DistanceIndexIfEESt6vectorIS4_SaIS4_EEEENS0_5__ops15_Iter_less_iterEET_SC_SC_T0_,
[2021-11-19 17:27:34]  which has no line number information.
[2021-11-19 17:27:34]  n 0x0000007ff3d0849c in ?? () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:28:12]  (gdb) c
[2021-11-19 17:28:21]  Continuing.
[2021-11-19 17:28:21]  ^C
[2021-11-19 17:28:23]  Thread 21 "carto_mock" received signal SIGINT, Interrupt.
[2021-11-19 17:28:23]  0x0000007ff3ceef94 in void std::__adjust_heap<__gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, long, flann::DistanceIndex<float>, __gnu_cxx::__ops::_Iter_less_iter>(__gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, long, long, flann::DistanceIndex<float>, __gnu_cxx::__ops::_Iter_less_iter) () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:28:23]  (gdb) n
[2021-11-19 17:28:24]  Single stepping until exit from function _ZSt13__adjust_heapIN9__gnu_cxx17__normal_iteratorIPN5flann13DistanceIndexIfEESt6vectorIS4_SaIS4_EEEElS4_NS0_5__ops15_Iter_less_iterEEvT_T0_SD_T1_T2_,
[2021-11-19 17:28:24]  which has no line number information.
[2021-11-19 17:28:24]  0x0000007ff3d08484 in ?? () from /lib/libpcl_segmentation.so.1.12
[2021-11-19 17:28:24]  (gdb) n
[2021-11-19 17:28:25]  Cannot find bounds of current function
[2021-11-19 17:28:25]  (gdb) n
[2021-11-19 17:28:27]  Cannot find bounds of current function
[2021-11-19 17:28:27]  (gdb) n
[2021-11-19 17:29:29]  Cannot find bounds of current function
[2021-11-19 17:29:29]  (gdb) c
[2021-11-19 17:29:30]  Continuing.
[2021-11-19 17:29:30]  ^C
[2021-11-19 17:29:32]  Thread 21 "carto_mock" received signal SIGINT, Interrupt.
[2021-11-19 17:29:32]  0x0000007ff3cee748 in __gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > > std::__unguarded_partition_pivot<__gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, __gnu_cxx::__ops::_Iter_less_iter>(__gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, __gnu_cxx::__normal_iterator<flann::DistanceIndex<float>*, std::vector<flann::DistanceIndex<float>, std::allocator<flann::DistanceIndex<float> > > >, __gnu_cxx::__ops::_Iter_less_iter) () from /lib/libpcl_segmentation.so.1.12
[

代码

int FusionStrategyUnknownObject::GetPclCluster(TransMsg& trans_msg)
{
    //Create the filtering object: downsample the dataset using a leaf size of 1cm
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_point (new pcl::PointCloud<pcl::PointXYZ>),cloud_filter (new pcl::PointCloud<pcl::PointXYZ>);
    cloud_point = cloud_;

    // Create the segmentation object for the planar model and set all the parameters
    pcl::SACSegmentation<pcl::PointXYZ> seg;
    pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
    pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_plane (new pcl::PointCloud<pcl::PointXYZ> ());

    // Optional
    seg.setOptimizeCoefficients (true);
    // Mandatory
    seg.setModelType (pcl::SACMODEL_PLANE);
    seg.setMethodType (pcl::SAC_RANSAC);
    seg.setMaxIterations (100);
    seg.setDistanceThreshold (0.01);

    int i=0, nr_points = (int) cloud_point->size ();
    // While 30% of the original cloud is still there
    int tmp_points = 0.3 * nr_points;
    while (cloud_point->size () > tmp_points)
    {
        // Segment the largest planar component from the remaining cloud
        seg.setInputCloud (cloud_point);
        seg.segment (*inliers, *coefficients);
        if (inliers->indices.size () == 0)
        {
          spdlog::info("[od_fusion] Could not estimate a planar model for the given dataset.");
          break;
        }

        // Extract the planar inliers from the input cloud
        pcl::ExtractIndices<pcl::PointXYZ> extract;
        extract.setInputCloud (cloud_point);
        extract.setIndices (inliers);
        extract.setNegative (false);

        // Get the points associated with the planar surface
        extract.filter (*cloud_plane);

        // Remove the planar inliers, extract the rest
        extract.setNegative (true);
        extract.filter (*cloud_filter);

        *cloud_point = *cloud_filter;
    }

    //Creating the KdTree object for the search method of the extraction
    pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
    tree->setInputCloud (cloud_point);

    std::vector<pcl::PointIndices> cluster_indices;
    pcl::EuclideanClusterExtraction<pcl::PointXYZ> ec;

    ec.setClusterTolerance (pcl_clustre_tolerance_);
    ec.setMinClusterSize (pcl_min_cluster_size_);
    ec.setMaxClusterSize (pcl_max_cluster_size_);
    ec.setSearchMethod (tree);
    ec.setInputCloud (cloud_point);
    ec.extract (cluster_indices);

    int cluster_size = cluster_indices.size();
    float min_x[cluster_size]={0.0};
    float max_x[cluster_size]={0.0};
    float min_z[cluster_size]={0.0};
    int j = 0;
    for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin (); it != cluster_indices.end (); ++it)
    {
        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_cluster (new pcl::PointCloud<pcl::PointXYZ>);
        for (std::vector<int>::const_iterator pit = it->indices.begin (); pit != it->indices.end (); ++pit)
        {
          cloud_cluster->push_back ((*cloud_point)[*pit]); //*
        }
        cloud_cluster->width = cloud_cluster->size ();
        spdlog::info("[od_fusion] --------------------cluster size : {0}", cloud_cluster->width);
        cloud_cluster->height = 1;
        cloud_cluster->is_dense = true;

        min_x[j] = cloud_cluster->points[0].x;
        max_x[j] = cloud_cluster->points[0].x;

        std::vector<float> cluster_depth;
        for(int i=1;i<cloud_cluster->size();i++)
        {
            if(min_x[j]>cloud_cluster->points[i].x)
            {
              min_x[j] = cloud_cluster->points[i].x;
            }
            if(max_x[j]<cloud_cluster->points[i].x)
            {
              max_x[j] = cloud_cluster->points[i].x;
            }

            cluster_depth.push_back(cloud_cluster->points[i].z);
        }

        GetMaxPercentDepth(cluster_depth, min_z[j]);

        float middle_x = min_x[j]+(max_x[j]-min_x[j])/2;
        struct bbox_xy_label object2;
        object2.bboxes.push_back(8);   //unknown object
        object2.bboxes.push_back(min_x[j]);
        object2.bboxes.push_back(min_z[j]);
        object2.bboxes.push_back(middle_x);
        object2.bboxes.push_back(min_z[j]);
        object2.bboxes.push_back(max_x[j]);
        object2.bboxes.push_back(min_z[j]);

        trans_msg.bboxes_vector.push_back(object2);
        j++;
    }
}

CMakeLists

find_package (PCL 1.12 REQUIRED)
include_directories(
      ....
      ${PCL_INCLUDE_DIRS}
    )
add_library(od_fusion SHARED
...
            src/strategy/strategy_dumper/src/fusion_strategy_dumper.cc
...        
    )

set(PCL_DIR /sdk/buildroot/output/rockchip_rk3568/host/aarch64-buildroot-linux-gnu/sysroot/lib)
link_directories(${PCL_LIBRARY_DIRS})
set(PCL_LIB
${PROJECT_SOURCE_DIR}/../3rdparty/flann/lib/libflann_cpp.so.1.9.1
# ${PCL_LIB_DIR}/libpcl_segmentation.so
${PCL_LIBRARIES}
)
4

0 回答 0