4 np.set_printoptions(precision=4)
7 from scipy
import spatial
11 if (x >= 0
and y >= 0):
12 theta = 180/np.pi * np.arctan(y/x)
13 elif (x < 0
and y >= 0):
14 theta = 180 - ((180/np.pi) * np.arctan(y/(-x)))
15 elif (x < 0
and y < 0):
16 theta = 180 + ((180/np.pi) * np.arctan(y/x))
17 elif ( x >= 0
and y < 0):
18 theta = 360 - ((180/np.pi) * np.arctan((-y)/x))
22 def pt2rs(point, gap_ring, gap_sector, num_ring, num_sector):
33 faraway = np.sqrt(x*x + y*y)
35 idx_ring = np.divmod(faraway, gap_ring)[0]
36 idx_sector = np.divmod(theta, gap_sector)[0]
38 if(idx_ring >= num_ring):
41 return int(idx_ring), int(idx_sector)
45 num_ring = sc_shape[0]
46 num_sector = sc_shape[1]
48 gap_ring = max_length/num_ring
49 gap_sector = 360/num_sector
52 sc_storage = np.zeros([enough_large, num_ring, num_sector])
53 sc_counter = np.zeros([num_ring, num_sector])
55 num_points = ptcloud.shape[0]
56 for pt_idx
in range(num_points):
57 point = ptcloud[pt_idx, :]
58 if np.isnan(point[0])
or np.isnan(point[1])
or np.isnan(point[2]):
61 point_height = point[2] + 2.0
63 idx_ring, idx_sector =
pt2rs(point, gap_ring, gap_sector, num_ring, num_sector)
65 if sc_counter[idx_ring, idx_sector] >= enough_large:
67 sc_storage[int(sc_counter[idx_ring, idx_sector]), idx_ring, idx_sector] = point_height
68 sc_counter[idx_ring, idx_sector] = sc_counter[idx_ring, idx_sector] + 1
70 sc = np.amax(sc_storage, axis=0)
76 return np.mean(sc, axis=1)
79 num_sectors = sc1.shape[1]
83 sim_for_each_cols = np.zeros(num_sectors)
84 for i
in range(num_sectors):
86 sc1 = np.roll(sc1, _one_step, axis=1)
91 for j
in range(num_sectors):
94 if (~np.any(col_j_1)
or ~np.any(col_j_2)):
99 cossim = np.dot(col_j_1, col_j_2) / (np.linalg.norm(col_j_1) * np.linalg.norm(col_j_2))
100 sum_of_cossim = sum_of_cossim + cossim
102 num_col_engaged = num_col_engaged + 1
105 if num_col_engaged == 0:
106 sim_for_each_cols[i] = 0.0
108 sim_for_each_cols[i] = sum_of_cossim / num_col_engaged
110 yaw_diff = np.argmax(sim_for_each_cols) + 1
111 sim = np.max(sim_for_each_cols)
114 return dist, yaw_diff
def distance_sc(sc1, sc2)
def ptcloud2sc(ptcloud, sc_shape, max_length)
def pt2rs(point, gap_ring, gap_sector, num_ring, num_sector)