mrdja.ransac.coreransaccuda.get_ransac_results_cuda

mrdja.ransac.coreransaccuda.get_ransac_results_cuda(points, num_points, threshold, num_iterations)[source]

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

Parameters:
  • points (np.ndarray) – 3D coordinates of the points as a numpy array with shape (num_points, 3).

  • num_points (int) – Number of points to use for RANSAC.

  • threshold (float) – Maximum distance to the plane.

  • num_iterations (int) – Number of iterations to compute the best plane.

Returns:

A dictionary with keys “best_plane”, “number_inliers”, and “indices_inliers”. “best_plane” is a numpy array with shape (4,) representing the best-fit plane in the form of [a, b, c, d], where the equation of the plane is ax + by + cz + d = 0. “number_inliers” is an int representing the number of inliers that fit the best-fit plane. “indices_inliers” is a numpy array with shape (num_inliers,) representing the indices of the inliers.

Return type:

dict

Example:

>>> import customransac
>>> import open3d as o3d
>>> import numpy as np
>>> import random
>>> pcd_filename = "/tmp/Lantegi/Kubic.ply"
>>> pcd = o3d.io.read_point_cloud(pcd_filename)
>>> pcd_points = np.asarray(pcd.points, dtype="float32")
>>> num_points = len(pcd_points)
>>> pcd_points_x = pcd_points[:, 0]
>>> pcd_points_y = pcd_points[:, 1]
>>> pcd_points_z = pcd_points[:, 2]
>>> threshold = 0.1
>>> num_iterations = 2
>>> list_num_points = list(range(num_points))
>>> random_points_indices_1 = np.array([], dtype="int64")
>>> random_points_indices_2 = np.array([], dtype="int64")
>>> random_points_indices_3 = np.array([], dtype="int64")
>>> for i in range(num_iterations):
>>>     random_points_indices = random.sample(list_num_points, 3)
>>>     random_points_indices_1 = np.append(random_points_indices_1, random_points_indices[0])
>>>     random_points_indices_2 = np.append(random_points_indices_2, random_points_indices[1])
>>>     random_points_indices_3 = np.append(random_points_indices_3, random_points_indices[2])
>>> plane_parameters, indices = customransac.get_best_plane_and_inliers(pcd_points_x, pcd_points_y, pcd_points_z, threshold, num_iterations, random_points_indices_1, random_points_indices_2, random_points_indices_3)
>>> plane_parameters
array([ 0.0012,  0.0012,  0.0012,  0.0012])
>>> inlier_cloud = pcd.select_by_index(inliers)
>>> inlier_cloud.paint_uniform_color([1.0, 0, 0])
>>> outlier_cloud = pcd.select_by_index(inliers, invert=True)
>>> o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud])