Ransaccuda Module
This module contains functions related to RANSAC and CUDA parallel processing.
Returns the fitting data for the best plane in the list of planes. |
|
Returns the fitting data for each plane in the list of planes. |
|
|
Computes the number of points that are below a threshold distance from a plane and their indices using CUDA parallel processing. |
|
Computes the number of points that are below a threshold distance from a plane and their indices using CUDA parallel processing. |
|
Computes the number of points that are below a threshold distance from a plane and their indices using CUDA parallel processing. |
Computes the number of inliers and the plane parameters for one iteration of the RANSAC algorithm using CUDA. |
|
Computes the number of inliers and the plane parameters for one iteration of the RANSAC algorithm using CUDA. |
|
|
Computes the best plane that fits a collection of points and the indices of the inliers. |
- ransaccuda.get_best_fitting_data_from_list_planes_cuda(points: ndarray, list_planes: List[ndarray], threshold: float) Dict[source]
Returns the fitting data for the best plane in the list of planes.
- Parameters:
points (np.ndarray) – The collection of points to fit the plane to.
list_planes (List[np.ndarray]) – The list of planes to fit to the points.
threshold (float) – The maximum distance from a point to the plane for it to be considered an inlier.
- Returns:
A dictionary containing the plane parameters, number of inliers, and their indices.
- Return type:
Dict
- Example:
>>> import rsaitehu.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])} >>> fitting_data = coreransac.get_fitting_data_from_list_planes(pcd_points, [dict_results["best_plane"]], threshold) >>> fitting_data [{'plane': array([-0.17535096, 0.45186984, -2.44615646, 5.69205427]), 'number_inliers': 153798, 'indices_inliers': array([ 0, 1, 2, ..., 248476, 248477, 248478])}] >>> best_fitting_data = coreransac.get_best_fitting_data_from_list_planes(pcd_points, [dict_results["best_plane"]], threshold) >>> best_fitting_data {'plane': array([-0.17535096, 0.45186984, -2.44615646, 5.69205427]), 'number_inliers': 153798, 'indices_inliers': array([ 0, 1, 2, ..., 248476, 248477, 248478])}
- ransaccuda.get_fitting_data_from_list_planes_cuda(points: ndarray, list_planes: List[ndarray], threshold: float) List[Dict][source]
Returns the fitting data for each plane in the list of planes.
- Parameters:
points (np.ndarray) – The collection of points to fit the plane to.
list_planes (List[np.ndarray]) – The list of planes to fit to the points.
threshold (float) – The maximum distance from a point to the plane for it to be considered an inlier.
- Returns:
A list of dictionaries containing the plane parameters, number of inliers, and their indices.
- Return type:
List[Dict]
- Example:
>>> import rsaitehu.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])} >>> fitting_data = coreransac.get_fitting_data_from_list_planes(pcd_points, [dict_results["best_plane"]], threshold) >>> fitting_data [{'plane': array([-0.17535096, 0.45186984, -2.44615646, 5.69205427]), 'number_inliers': 153798, 'indices_inliers': array([ 0, 1, 2, ..., 248476, 248477, 248478])}]
- ransaccuda.get_how_many_and_which_below_threshold_between_plane_and_points_and_their_indices_cuda(points: ndarray, d_points_x: ndarray, d_points_y: ndarray, d_points_z: ndarray, plane: Tuple[float, float, float, float], threshold: float) Tuple[int, List[int]][source]
Computes the number of points that are below a threshold distance from a plane and their indices using CUDA parallel processing.
- Parameters:
points (np.ndarray) – The array of points in the format (x, y, z).
points_x (np.ndarray) – The x-coordinates of the points.
points_y (np.ndarray) – The y-coordinates of the points.
points_z (np.ndarray) – The z-coordinates of the points.
d_points_x (np.ndarray) – The x-coordinates of the points in device memory.
d_points_y (np.ndarray) – The y-coordinates of the points in device memory.
d_points_z (np.ndarray) – The z-coordinates of the points in device memory.
plane (Tuple[float, float, float, float]) – The coefficients of the plane equation.
threshold (float) – The threshold distance from the plane.
- Returns:
The number of points below the threshold and their indices.
- Return type:
Tuple[int, List[int]]
- ransaccuda.get_how_many_below_threshold_between_line_and_points_cuda(points: ndarray, d_points_x: ndarray, d_points_y: ndarray, d_points_z: ndarray, line_two_points: Tuple[Tuple[float, float, float], Tuple[float, float, float]], threshold: float) Tuple[int, List[int]][source]
Computes the number of points that are below a threshold distance from a plane and their indices using CUDA parallel processing.
- Parameters:
points (np.ndarray) – The array of points in the format (x, y, z).
points_x (np.ndarray) – The x-coordinates of the points.
points_y (np.ndarray) – The y-coordinates of the points.
points_z (np.ndarray) – The z-coordinates of the points.
d_points_x (np.ndarray) – The x-coordinates of the points in device memory.
d_points_y (np.ndarray) – The y-coordinates of the points in device memory.
d_points_z (np.ndarray) – The z-coordinates of the points in device memory.
plane (Tuple[float, float, float, float]) – The coefficients of the plane equation.
threshold (float) – The threshold distance from the plane.
- Returns:
The number of points below the threshold and their indices.
- Return type:
Tuple[int, List[int]]
- ransaccuda.get_how_many_below_threshold_between_plane_and_points_cuda(points: ndarray, d_points_x: ndarray, d_points_y: ndarray, d_points_z: ndarray, plane: Tuple[float, float, float, float], threshold: float) int[source]
Computes the number of points that are below a threshold distance from a plane and their indices using CUDA parallel processing.
- Parameters:
points (np.ndarray) – The array of points in the format (x, y, z).
points_x (np.ndarray) – The x-coordinates of the points.
points_y (np.ndarray) – The y-coordinates of the points.
points_z (np.ndarray) – The z-coordinates of the points.
d_points_x (np.ndarray) – The x-coordinates of the points in device memory.
d_points_y (np.ndarray) – The y-coordinates of the points in device memory.
d_points_z (np.ndarray) – The z-coordinates of the points in device memory.
plane (Tuple[float, float, float, float]) – The coefficients of the plane equation.
threshold (float) – The threshold distance from the plane.
- Returns:
The number of points below the threshold and their indices.
- Return type:
Tuple[int, List[int]]
- ransaccuda.get_ransac_line_iteration_results_cuda(points: ndarray, d_points_x: DeviceNDArray, d_points_y: DeviceNDArray, d_points_z: DeviceNDArray, threshold: float, random_points: ndarray) dict[source]
Computes the number of inliers and the plane parameters for one iteration of the RANSAC algorithm using CUDA.
- Parameters:
points (np.ndarray) – Array of points.
points_x (np.ndarray) – X coordinates of the points.
points_y (np.ndarray) – Y coordinates of the points.
points_z (np.ndarray) – Z coordinates of the points.
d_points_x (cuda.devicearray.DeviceNDArray) – Device array of X coordinates of the points.
d_points_y (cuda.devicearray.DeviceNDArray) – Device array of Y coordinates of the points.
d_points_z (cuda.devicearray.DeviceNDArray) – Device array of Z coordinates of the points.
num_points (int) – Number of random points to select for each iteration.
threshold (float) – Maximum distance to the plane.
- Returns:
Dictionary with the plane parameters, the number of inliers, and the indices of the inliers.
- Return type:
dict
- ransaccuda.get_ransac_plane_iteration_results_cuda(points: ndarray, points_x: ndarray, points_y: ndarray, points_z: ndarray, d_points_x: DeviceNDArray, d_points_y: DeviceNDArray, d_points_z: DeviceNDArray, num_points: int, threshold: float) dict[source]
Computes the number of inliers and the plane parameters for one iteration of the RANSAC algorithm using CUDA.
- Parameters:
points (np.ndarray) – Array of points.
points_x (np.ndarray) – X coordinates of the points.
points_y (np.ndarray) – Y coordinates of the points.
points_z (np.ndarray) – Z coordinates of the points.
d_points_x (cuda.devicearray.DeviceNDArray) – Device array of X coordinates of the points.
d_points_y (cuda.devicearray.DeviceNDArray) – Device array of Y coordinates of the points.
d_points_z (cuda.devicearray.DeviceNDArray) – Device array of Z coordinates of the points.
num_points (int) – Number of random points to select for each iteration.
threshold (float) – Maximum distance to the plane.
- Returns:
Dictionary with the plane parameters, the number of inliers, and the indices of the inliers.
- Return type:
dict
- ransaccuda.get_ransac_plane_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:
>>> from rsaitehu import ransaccuda >>> import open3d as o3d >>> import numpy as np >>> import random >>> 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 = ransaccuda.get_ransac_plane_results_cuda(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])