mrdja.ransac.coreransac.get_ransac_plane_iteration_results

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

Returns the results of one iteration of the RANSAC algorithm for plane fitting.

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 seed to initialize the random number generator. It returns a dictionary containing the current plane parameters, number of inliers, and their indices. The keys of the dictionary are current_random_points, “current_plane”, “threshold”, “number_inliers”, and “indices_inliers”, respectively. The type of the values of the dictionary are np.ndarray, np.ndarray, float, int, and np.ndarray, respectively.

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.

  • 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 current plane parameters, number of inliers, and their indices, as well as the three random points sampled to create the plane.

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_iteration_results(pcd_points, threshold, seed = 42)
>>> dict_results
>>> {'current_random_points': array([[1.61072648, 1.83984375, 1.91796875],
>>> [3.00390625, 2.68674755, 2.01953125],
>>> [2.10068583, 2.34765625, 2.14453125]]),
>>> 'current_plane': array([ 0.14030194, -0.2658808 ,  0.29252566, -0.297864  ]),
>>> 'threshold': 0.1,
>>> 'number_inliers': 34283,
>>> 'indices_inliers': array([ 98356, 101924, 101956, ..., 271055, 271245, 271246])}
>>> 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_iteration_results_example