-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
157 lines (128 loc) · 4.61 KB
/
test_utils.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import numpy as np
import open3d as o3d
import copy
def get_init_position(pnt,eps,min_points):
""" extract drone pointcloud
Args:
pnt: N x 3 point clouds
eps: the distance to neighbors in a cluster
min_points: the minimum number of points
Returns:
[ndarray]: N x 3 point clouds
"""
pointcloud = copy.deepcopy(pnt)
labels = np.array(pointcloud.cluster_dbscan(eps, min_points, print_progress=True))
dis = []
for label_i in np.unique(labels):
person_label = np.array(np.where(labels==label_i))
person_pnt = pointcloud.select_by_index(person_label[0])
if (np.linalg.norm(person_pnt.get_center() - np.array([0,0,0]))) == 0:
dis.append(1000)
else:
dis.append(np.linalg.norm(person_pnt.get_center() - np.array([0,0,0])))
index = np.where(dis == np.min(dis))
drone_label = np.array(np.where(labels==index[0][0]-1))
return pointcloud.select_by_index(drone_label[0])
def get_drone(pnt,target,eps,min_points):
""" extract drone pointcloud
Args:
pnt: N x 3 point clouds
eps: the distance to neighbors in a cluster
min_points: the minimum number of points
target: target drone pcd
Returns:
[ndarray]: N x 3 point clouds
"""
pointcloud = copy.deepcopy(pnt)
labels = np.array(pointcloud.cluster_dbscan(eps, min_points, print_progress=True))
dis = []
for label_i in np.unique(labels):
try:
person_label = np.array(np.where(labels==label_i))
person_pnt = pointcloud.select_by_index(person_label[0])
print(person_pnt)
if (np.linalg.norm(person_pnt.get_center() - np.array([0,0,0]))) == 0:
dis.append(1000)
else:
dis.append(np.linalg.norm(person_pnt.get_center() - target.get_center()))
except RuntimeError:
dis.append(1000)
pass
dis = np.asarray(dis)
print(dis)
if np.min(dis) > 0.1:
flag = 0
else:
flag = 1
index = np.where(dis == np.min(dis))
print(index)
drone_label = np.array(np.where(labels==index[0][0]-1))
if abs(len(target.points)-len(pointcloud.select_by_index(drone_label[0]).points))>100:
flag = 0
else:
flag = 1
return pointcloud.select_by_index(drone_label[0]),flag
def get_roi_drone(pnt,target,eps,):
""" extract drone pointcloud
Args:
pnt: N x 3 point clouds
eps: the distance to neighbors in a cluster
target: target drone pcd
Returns:
[ndarray]: N x 3 point clouds
"""
num = len(np.asarray(target.points))
if num > 200:
num = 80
pointcloud = copy.deepcopy(pnt)
labels = np.array(pointcloud.cluster_dbscan(eps, int(0.625*num), print_progress=True))
dis = []
for label_i in np.unique(labels):
try:
person_label = np.array(np.where(labels==label_i))
person_pnt = pointcloud.select_by_index(person_label[0])
print(person_pnt)
if (np.linalg.norm(person_pnt.get_center() - np.array([0,0,0]))) == 0:
dis.append(1000)
else:
dis.append(abs(np.linalg.norm(person_pnt.get_center() - target.get_center())))
except RuntimeError:
dis.append(1000)
pass
dis = np.asarray(dis)
print(dis)
if np.min(dis) > 0.1:
flag = 0
else:
flag = 1
index = np.where(dis == np.min(dis))
print(index)
if len(np.where(np.unique(labels)==-1)[0]) ==0:
drone_label = np.array(np.where(labels==index[0][0]))
if abs(len(target.points)-len(pointcloud.select_by_index(drone_label[0]).points))>15:
flag = 0
else:
flag = 1
else:
drone_label = np.array(np.where(labels==index[0][0]-1))
if (index[0][0]-1) == -1:
flag = 0
else:
flag = 1
if abs(len(target.points)-len(pointcloud.select_by_index(drone_label[0]).points))>15:
flag = 0
else:
flag = 1
return pointcloud.select_by_index(drone_label[0]),flag
def get_roi(center,data,therhold):
x_min = center[0] - therhold
x_max = center[0] + therhold
y_min = center[1] - therhold
y_max = center[1] + therhold
z_min = center[2] - 0.5
z_max = center[2] + 0.5
# 使用 NumPy 的布尔索引筛选出符合条件的向量
mask = (data[:, 0] >= x_min) & (data[:, 0] <= x_max) & \
(data[:, 1] >= y_min) & (data[:, 1] <= y_max) & \
(data[:, 2] >= z_min) & (data[:, 2] <= z_max)
return data[mask]