Skip to content

Proposal for New Algorithm Sample: Robust Least-Squares Rectangle Fitting (2D LiDAR) #30

@diogoccprado

Description

@diogoccprado

Algorithm Name
Robust Least-Squares Rectangle Fitting (with robust loss)

Description
This sample estimates an oriented rectangle for each detected object in a 2D LiDAR scan. The scan is first segmented into clusters (each cluster represents one object), then robust least-squares fitting is applied per cluster to output one rectangle per object. Using a robust loss reduces the influence of outliers within each cluster, improving stability under noise and partial occlusions.

Plan for Implementation

  1. Integration and Interface
  • Add a new sample script under src/simulations/perception/point_cloud_rectangle_fitting/ following the existing L-shape fitting sample structure (same I/O and plotting style).
  1. Rectangle Parameterization + Initialization
  • Reuse the existing clustering/object-segmentation step, then run the fitter independently for each cluster to produce multiple rectangles in a scene.
  • Parameterize rectangle as (cx, cy, theta, width, length) (or half-sizes).
  • Use a stable initialization (PCA-based orientation + extents, or the existing L-shape estimate as an initial guess).
  • Ensure width/length remain positive during optimization (e.g., optimize half-sizes or log-parameters).
  1. Residuals and Optimization
  • Define one residual per point as the distance to the closest rectangle edge (≈ 0 when the point lies on the rectangle boundary).
  • Solve with scipy.optimize.least_squares using a robust loss (soft_l1 or huber) and an f_scale value in meters that matches expected inlier noise.
  • Use a solver method compatible with robust losses (e.g., trf).
  1. Visualization and Testing
  • Add a Matplotlib animation showing the rectangle updating during optimization (iterations / parameter updates).
  • Add unit tests with synthetic rectangles: edge points + Gaussian noise + injected outliers (animation disabled).
  • Validate using measurable errors (e.g., center error, yaw error, size error, and/or IoU vs ground truth rectangle).

References
SciPy least_squares (robust losses: huber, soft_l1, cauchy):
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html

Robust regression / M-estimation overview (intuition for downweighting outliers):
https://pmc.ncbi.nlm.nih.gov/articles/PMC6167755/

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions