8484# R = (U*V')';%回転行列の計算
8585# t = mm - R*ms;%並進ベクトルの計算
8686
87+ def update_homogenerous_matrix (Hin , R , T ):
88+ print (R )
89+
90+ H = np .matrix (np .zeros ((3 , 3 ))) # translation vector
91+
92+ H [0 , 0 ] = R [0 , 0 ]
93+ H [1 , 0 ] = R [1 , 0 ]
94+ H [0 , 1 ] = R [0 , 1 ]
95+ H [1 , 1 ] = R [1 , 1 ]
96+ H [2 , 2 ] = 1.0
97+
98+ H [0 , 2 ] = T [0 , 0 ]
99+ H [1 , 2 ] = T [1 , 0 ]
100+
101+ if Hin is None :
102+ return H
103+ else :
104+ return Hin * H
105+
87106
88107def ICP_matching (pdata , data ):
89108 R = np .eye (2 ) # rotation matrix
90109 T = np .zeros ((2 , 1 )) # translation vector
110+ H = None # translation vector
91111
92112 # ICP
93113 EPS = 0.0001
@@ -102,11 +122,10 @@ def ICP_matching(pdata, data):
102122
103123 error = nearest_neighbor_assosiation (pdata , data )
104124 Rt , Tt = SVD_motion_estimation (pdata , data )
105- print (error )
106125
107126 data = (Rt * data ) + Tt
108- R = R * Rt
109- T = R * T + Tt
127+
128+ H = update_homogenerous_matrix ( H , Rt , Tt )
110129
111130 dError = abs (preError - error )
112131 preError = error
@@ -118,6 +137,12 @@ def ICP_matching(pdata, data):
118137 elif maxIter <= count :
119138 break
120139
140+ R = np .matrix (H [0 :2 , 0 :2 ])
141+ T = np .matrix (H [0 :2 , 2 ])
142+ print (H )
143+ print (R )
144+ print (T )
145+
121146 return R , T
122147
123148
@@ -173,10 +198,11 @@ def main():
173198 # print(pdata)
174199 data = np .matrix (np .vstack ((cx , cy )))
175200 # print(data)
201+ odata = data [:, :]
176202
177203 R , T = ICP_matching (pdata , data )
178204
179- fdata = (R * data ) + T
205+ fdata = (R * odata ) + T
180206
181207 plt .plot (px , py , ".b" )
182208 plt .plot (cx , cy , ".r" )
0 commit comments