Skip to content

Build the kd-tree once in L-shape fitting segmentation - #329

Open
Hung1510 wants to merge 1 commit into
ShisatoYano:mainfrom
Hung1510:refactor-lshape-clustering
Open

Hung1510 wants to merge 1 commit into
ShisatoYano:mainfrom
Hung1510:refactor-lshape-clustering

Conversation

@Hung1510

Copy link
Copy Markdown

Summary

Closes #316

_adaptive_range_segmentation now builds the kd-tree once, from a copy of the point cloud, before the loop. Building it inside the loop sorted point_cloud in place while the loop was iterating over it.

I went with the first option from the issue: one neighborhood per point without the queue (which only ever held the starting point), and _merge_clusters still joins neighborhoods that share points. It keeps the method short and matches what the code was already doing.

How I checked it works

  • Recorded every detected rectangle of point_cloud_rectangle_fitting with np.random.seed(0) before and after: all 603 rectangles over 201 updates are identical. The simulation also runs in about 8 s instead of 18 s.
  • Added test_segmentation_gives_one_neighborhood_per_point_and_keeps_input_order to test/test_l_shape_fitting_detector.py. It fails before the change (the input list gets reordered) and passes after.
  • Ran . run_test_suites.sh: 176 passed.

Images

Last frame of point_cloud_rectangle_fitting with np.random.seed(0), before and after (identical):

Before:
avc-316_before

After:
avc-316_after

Book

  • This PR doesn't change code that the book describes, or I updated those pages
    (section 9.2 is not written yet)

_adaptive_range_segmentation built a KdTree for every point, and KdTree sorts
the list it is given in place, which reordered point_cloud while the loop was
iterating over it. points_queue only ever held the starting point, so the
while loop ran once per point.

Build the tree once from a copy of the point cloud, and compute one
neighborhood per point without the queue. _merge_clusters still joins the
neighborhoods that share points into one cluster per object.

The detected rectangles of point_cloud_rectangle_fitting are unchanged (all
603 rectangles over 201 updates compared with np.random.seed(0)), and the
simulation runs in about 8 s instead of 18 s.

Closes ShisatoYano#316

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up the clustering in L-shape fitting: build the kd-tree once and don't sort the list being iterated

1 participant