PointCloud.segment_plane#
- PointCloud.segment_plane(**kwargs: Any) tuple[Any, PointCloud, PointCloud][source][source]#
Find the dominant plane using RANSAC
- Parameters:
distance_threshold (float) – largest distance of a point from the plane for it to count as part of the plane, in the units of the points
ransac_n (int, optional) – number of points sampled to fit each candidate plane, defaults to 3
num_iterations (int, optional) – number of candidate planes tried, defaults to 1000
probability (float, optional) – required probability of finding the best plane, Open3D’s default is 0.99999999
- Returns:
plane parameters, points on the plane, all the other points
- Return type:
ndarray(4),
PointCloud,PointCloud- Raises:
TypeError –
distance_thresholdis not given
Uses RANSAC to fit a plane \(aX + bY + cZ + d = 0\) to the points. Each iteration fits a plane to
ransac_nrandomly chosen points, and keeps the plane that has the most points withindistance_thresholdof it. The arguments are passed toopen3d.geometry.PointCloud.segment_plane.The first return value is the array \((a, b, c, d)\). The second is a new point cloud of the points within
distance_thresholdof the plane, the inliers, and the third is a new point cloud of the remaining points. The original point cloud is not changed. Points of an object that lie close to the plane, such as the foot of an object standing on a ground plane, are inliers.Changed in version 2.5.0: The default
num_iterationsis 1000. It was 100, which sometimes returned a poor plane.RANSAC chooses its points at random, so the plane and the number of inliers differ slightly from run to run. With few iterations a poor plane is sometimes returned. Increase
num_iterations, or seed Open3D’s random number generator withopen3d.utility.random.seed(n)to get the same result every time.Examples
>>> import numpy as np >>> from machinevisiontoolbox import PointCloud >>> rng = np.random.default_rng(0) >>> ground = np.vstack((rng.random((2, 300)), np.zeros(300))) # z = 0 >>> objects = rng.random((3, 100)) + np.array([[0], [0], [0.5]]) # above it >>> pc = PointCloud(np.hstack((ground, objects))) >>> plane, on_plane, rest = pc.segment_plane(distance_threshold=0.01) >>> len(on_plane), len(rest) (300, 100)
See also