Skip to content

Commit 124fb91

Browse files
committed
keep coding
1 parent 883df8f commit 124fb91

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

SLAM/iterative_closest_point/iterative_closest_point.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,37 +94,56 @@ def ICP_matching(pdata, data):
9494
maxIter = 100
9595

9696
dError = 1000.0
97+
preError = 1000.0
9798
count = 0
9899

99100
while dError >= EPS:
100101
count += 1
101102

103+
error = nearest_neighbor_assosiation(pdata, data)
102104
Rt, Tt = SVD_motion_estimation(pdata, data)
103105
# print(count)
106+
print(error)
104107

108+
data = (Rt * data) + Tt
105109
R = R * Rt
106110
T = R * T + Tt
107111

108-
if maxIter <= count:
109-
break
112+
dError = abs(preError - error)
113+
preError = error
110114

111-
# preError = 0
115+
if dError <= EPS:
116+
break
117+
elif maxIter <= count:
118+
break
112119

113120
return R, T
114121

115122

123+
def nearest_neighbor_assosiation(pdata, data):
124+
125+
ddata = pdata - data
126+
# print(ddata)
127+
128+
d = np.linalg.norm(ddata, axis=0)
129+
130+
error = sum(d)
131+
132+
return error
133+
134+
116135
def SVD_motion_estimation(pdata, data):
117136

118137
pm = np.mean(pdata, axis=1)
119138
cm = np.mean(data, axis=1)
120139

121-
pshift = pdata - pm
122-
cshift = data - cm
140+
pshift = np.matrix(pdata - pm)
141+
cshift = np.matrix(data - cm)
123142

124143
W = pshift * cshift.T
125144
u, s, vh = np.linalg.svd(W)
126145

127-
R = (u * vh.T).T
146+
R = (u * vh).T
128147
t = pm - R * cm
129148

130149
return R, t

0 commit comments

Comments
 (0)