mrdja.ransac.coreransac.get_ransac_plane_results

mrdja.ransac.coreransac.get_ransac_plane_results(points: ndarray, threshold: float, num_iterations: int, len_points: int | None = None, seed: int | None = None) dict[source]

Computes the best plane that fits a collection of points and the indices of the inliers.

This functions expects a collection of points, the number of points in the collection, the maximum distance from a point to the plane for it to be considered an inlier, and the number of iterations to run the RANSAC algorithm. It returns a dictionary containing the best plane parameters, number of inliers, and their indices. The keys of the dictionary are “best_plane”, “number_inliers”, and “indices_inliers”, respectively. The type of the values of the dictionary are np.ndarray, int, and np.ndarray, respectively. Reproducibility is enforced by setting the seed parameter to a fixed value.

Parameters:
  • points (np.ndarray) – The collection of points to fit the plane to.

  • threshold (float) – The maximum distance from a point to the plane for it to be considered an inlier.

  • num_iterations (int) – The number of iterations to run the RANSAC algorithm.

  • len_points (Optional[int]) – The number of points in the collection of points.

  • seed (Optional[int]) – The seed to initialize the random number generator.

Returns:

A dictionary containing the best plane parameters, number of inliers, and their indices.

Return type:

dict

Example:

>>> import mrdja.ransac.coreransac as coreransac
>>> import open3d as o3d
>>> import numpy as np
>>> import random
>>> import open3d as o3d
>>> dataset = o3d.data.OfficePointClouds()
>>> pcds_offices = []
>>> for pcd_path in dataset.paths:
>>>     pcds_offices.append(o3d.io.read_point_cloud(pcd_path))
>>> office_pcd = pcds_offices[0]
>>> pcd_points = np.asarray(office_pcd.points)
>>> threshold = 0.1
>>> num_iterations = 20
>>> dict_results = coreransac.get_ransac_plane_results(pcd_points, threshold, num_iterations, seed = 42)
>>> dict_results
{'best_plane': array([-0.17535096,  0.45186984, -2.44615646,  5.69205427]),
'number_inliers': 153798,
'indices_inliers': array([     0,      1,      2, ..., 248476, 248477, 248478])}
>>> inliers = dict_results["indices_inliers"]
>>> inlier_cloud = office_pcd.select_by_index(inliers)
>>> inlier_cloud.paint_uniform_color([1.0, 0, 0])
>>> outlier_cloud = office_pcd.select_by_index(inliers, invert=True)
>>> o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud])

coreransac_get_ransac_plane_results_example