-
Notifications
You must be signed in to change notification settings - Fork 16
/
plane_detection.py
66 lines (48 loc) · 1.77 KB
/
plane_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from utils import *
def DetectMultiPlanes(points, min_ratio=0.05, threshold=0.01, iterations=1000):
""" Detect multiple planes from given point clouds
Args:
points (np.ndarray):
min_ratio (float, optional): The minimum left points ratio to end the Detection. Defaults to 0.05.
threshold (float, optional): RANSAC threshold in (m). Defaults to 0.01.
Returns:
[List[tuple(np.ndarray, List)]]: Plane equation and plane point index
"""
plane_list = []
N = len(points)
target = points.copy()
count = 0
while count < (1 - min_ratio) * N:
w, index = PlaneRegression(
target, threshold=threshold, init_n=3, iter=iterations)
count += len(index)
plane_list.append((w, target[index]))
target = np.delete(target, index, axis=0)
return plane_list
if __name__ == "__main__":
import random
import time
points = ReadPlyPoint('Data/test1.ply')
# pre-processing
#points = RemoveNan(points)
#points = DownSample(points,voxel_size=0.003)
points = RemoveNoiseStatistical(points, nb_neighbors=50, std_ratio=0.5)
#DrawPointCloud(points, color=(0.4, 0.4, 0.4))
t0 = time.time()
results = DetectMultiPlanes(points, min_ratio=0.05, threshold=0.005, iterations=2000)
print('Time:', time.time() - t0)
planes = []
colors = []
for _, plane in results:
r = random.random()
g = random.random()
b = random.random()
color = np.zeros((plane.shape[0], plane.shape[1]))
color[:, 0] = r
color[:, 1] = g
color[:, 2] = b
planes.append(plane)
colors.append(color)
planes = np.concatenate(planes, axis=0)
colors = np.concatenate(colors, axis=0)
DrawResult(planes, colors)