@@ -116,13 +116,25 @@ def artagcallback(i):
116
116
117
117
118
118
def calculate_extrinsic (positions , K_matrix , end_effector_positions ):
119
+ min_error = 10000000000000000
119
120
p = get_p (K_matrix , positions )
120
121
P = get_P (end_effector_positions )
121
- M = get_projection_matrix (p , P )
122
- K ,R = linalg .rq (M [:,0 :3 ])
122
+ for i in range (0 ,1000 ):
123
+ indices = np .random .randint (0 , 100 , size = 6 )
124
+ M = get_projection_matrix (p [indices ,:], P [indices ,:])
125
+ homogeneous_P = np .hstack ((P , np .ones ((P .shape [0 ], 1 ))))
126
+ estimated_p = np .matmul (M ,homogeneous_P .T )
127
+ estimated_p = estimated_p / estimated_p [2 ,:]
128
+ error = np .linalg .norm (p - estimated_p [0 :2 ,:].T )
129
+ print (error )
130
+ if error < min_error :
131
+ min_error = error
132
+ final_M = M
133
+ K ,R = linalg .rq (final_M [:,0 :3 ])
123
134
print (K / K [2 ,2 ])
124
135
T = np .matmul (np .linalg .inv (K ),M [:,3 ])
125
136
H = np .vstack ((np .hstack ((R ,T .reshape ((3 ,1 )))),np .array ([[0 ,0 ,0 ,1 ]])))
137
+ print (H )
126
138
return H
127
139
128
140
def get_projection_matrix (p , P ):
@@ -156,4 +168,10 @@ def get_P(end_effector_position):
156
168
return point_3D_world_frame
157
169
158
170
if __name__ == "__main__" :
159
- main (30 )
171
+ < << << << HEAD
172
+ main (30 )
173
+ == == == =
174
+ main (100 )
175
+ # calib_info = np.load("calibration_info.npz")
176
+ # calculate_extrinsic(calib_info['position'], calib_info['camerainfo'], calib_info['forward_kinematics'])
177
+ >> >> >> > 00 f3b8d0a97eda761ca978e46306ced5397a027d
0 commit comments