@@ -27,8 +27,8 @@ def icp_matching(previous_points, current_points):
2727 """
2828 H = None # homogeneous transformation matrix
2929
30- dError = 1000.0
31- preError = 1000.0
30+ dError = np . inf
31+ preError = np . inf
3232 count = 0
3333
3434 while dError >= EPS :
@@ -37,8 +37,9 @@ def icp_matching(previous_points, current_points):
3737 if show_animation : # pragma: no cover
3838 plt .cla ()
3939 # for stopping simulation with the esc key.
40- plt .gcf ().canvas .mpl_connect ('key_release_event' ,
41- lambda event : [exit (0 ) if event .key == 'escape' else None ])
40+ plt .gcf ().canvas .mpl_connect (
41+ 'key_release_event' ,
42+ lambda event : [exit (0 ) if event .key == 'escape' else None ])
4243 plt .plot (previous_points [0 , :], previous_points [1 , :], ".r" )
4344 plt .plot (current_points [0 , :], current_points [1 , :], ".b" )
4445 plt .plot (0.0 , 0.0 , "xr" )
@@ -47,15 +48,18 @@ def icp_matching(previous_points, current_points):
4748
4849 indexes , error = nearest_neighbor_association (previous_points , current_points )
4950 Rt , Tt = svd_motion_estimation (previous_points [:, indexes ], current_points )
50-
5151 # update current points
5252 current_points = (Rt @ current_points ) + Tt [:, np .newaxis ]
5353
54- H = update_homogeneous_matrix (H , Rt , Tt )
54+ dError = preError - error
55+ print ("Residual:" , error )
56+
57+ if dError < 0 : # prevent matrix H changing, exit loop
58+ print ("Not Converge..." , preError , dError , count )
59+ break
5560
56- dError = abs (preError - error )
5761 preError = error
58- print ( "Residual:" , error )
62+ H = update_homogeneous_matrix ( H , Rt , Tt )
5963
6064 if dError <= EPS :
6165 print ("Converge" , error , dError , count )
0 commit comments