@@ -27,8 +27,8 @@ def icp_matching(previous_points, current_points):
27
27
"""
28
28
H = None # homogeneous transformation matrix
29
29
30
- dError = 1000.0
31
- preError = 1000.0
30
+ dError = np . inf
31
+ preError = np . inf
32
32
count = 0
33
33
34
34
while dError >= EPS :
@@ -37,8 +37,9 @@ def icp_matching(previous_points, current_points):
37
37
if show_animation : # pragma: no cover
38
38
plt .cla ()
39
39
# 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 ])
42
43
plt .plot (previous_points [0 , :], previous_points [1 , :], ".r" )
43
44
plt .plot (current_points [0 , :], current_points [1 , :], ".b" )
44
45
plt .plot (0.0 , 0.0 , "xr" )
@@ -47,15 +48,18 @@ def icp_matching(previous_points, current_points):
47
48
48
49
indexes , error = nearest_neighbor_association (previous_points , current_points )
49
50
Rt , Tt = svd_motion_estimation (previous_points [:, indexes ], current_points )
50
-
51
51
# update current points
52
52
current_points = (Rt @ current_points ) + Tt [:, np .newaxis ]
53
53
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
55
60
56
- dError = abs (preError - error )
57
61
preError = error
58
- print ( "Residual:" , error )
62
+ H = update_homogeneous_matrix ( H , Rt , Tt )
59
63
60
64
if dError <= EPS :
61
65
print ("Converge" , error , dError , count )
0 commit comments