ethz-asl / segmap

A map representation based on 3D segments
BSD 3-Clause "New" or "Revised" License
1.07k stars 393 forks source link

Slow euclidean segmentation #143

Closed brunoeducsantos closed 5 years ago

brunoeducsantos commented 5 years ago

Hi , I implement a euclidean segmentation using segmenter from segmatch inside a cloud call back:


//Params to segmentation
    std::vector<bool> is_point_modified(pc->size(), false);
    std::vector<int64_t> points_mapping;
    SegmentedCloud segmented_cloud = new SegmentedCloud();

     // Build a kd-tree of the cloud.
    KdTreePointsNeighborsProvider<MapPoint> points_neighbors_provider;
    points_neighbors_provider.update(pc,points_mapping); 

     // Estimate normals if necessary.
    PointNormals empty_normals;
    PointNormals const * normals = &empty_normals;
    std::unique_ptr<NormalEstimator> normal_estimator;
    if (segmenter_type_ == "SimpleSmoothnessConstraints" ||
        segmenter_type_ == "IncrementalSmoothnessConstraints") {
        // Create normal estimator
        normal_estimator = NormalEstimator::create(
            normal_estimator_type_, radius_for_normal_estimation_m_);

        // Estimate normals
        // All points are considered new points.
        std::vector<int> new_points_indices(pc->size());
        std::iota(new_points_indices.begin(), new_points_indices.end(), 0u);
        normal_estimator->updateNormals(*pc, { }, new_points_indices, points_neighbors_provider);
        normals = &normal_estimator->getNormals();
     }

     //Cluster segmentation
    std::vector<Id> cluster_ids_to_segment_id;
    std::vector<std::pair<Id, Id>> renamed_segments;

    SegmenterFactory<MapPoint> segfac(params);
    std::unique_ptr<Segmenter<MapPoint>> seg = segfac.create();

    seg->segment(*normals, is_point_modified,
               *pc, points_neighbors_provider,
               segmented_cloud, cluster_ids_to_segment_id,
               renamed_segments);

Although, it takes a few seconds to segment a cloud. Is there any approach to improve performance? Regards, Bruno