replace .dot by @

This commit is contained in:
davidpagnon 2024-01-25 11:02:58 +01:00
parent 070692afaf
commit bd453fcb58
8 changed files with 24 additions and 24 deletions

View File

@ -79,10 +79,10 @@ def rotate_cam(r, t, ang_x=np.pi, ang_y=0, ang_z=0):
r_ax_x = np.array([1,0,0, 0,np.cos(ang_x),-np.sin(ang_x), 0,np.sin(ang_x),np.cos(ang_x)]).reshape(3,3)
r_ax_y = np.array([np.cos(ang_y),0,np.sin(ang_y), 0,1,0, -np.sin(ang_y),0,np.cos(ang_y)]).reshape(3,3)
r_ax_z = np.array([np.cos(ang_z),-np.sin(ang_z),0, np.sin(ang_z),np.cos(ang_z),0, 0,0,1]).reshape(3,3)
r_ax = r_ax_z.dot(r_ax_y).dot(r_ax_x)
r_ax = r_ax_z @ r_ax_y @ r_ax_x
r_ax_h = np.block([[r_ax,np.zeros(3).reshape(3,1)], [np.zeros(3), 1]])
r_ax_h__rt_h = r_ax_h.dot(rt_h)
r_ax_h__rt_h = r_ax_h @ rt_h
r = r_ax_h__rt_h[:3,:3]
t = r_ax_h__rt_h[:3,3]

View File

@ -129,7 +129,7 @@ def world_to_camera_persp(r, t):
'''
r = r.T
t = - r.dot(t)
t = - r @ t
return r, t
@ -144,10 +144,10 @@ def rotate_cam(r, t, ang_x=np.pi, ang_y=0, ang_z=0):
r_ax_x = np.array([1,0,0, 0,np.cos(ang_x),-np.sin(ang_x), 0,np.sin(ang_x),np.cos(ang_x)]).reshape(3,3)
r_ax_y = np.array([np.cos(ang_y),0,np.sin(ang_y), 0,1,0, -np.sin(ang_y),0,np.cos(ang_y)]).reshape(3,3)
r_ax_z = np.array([np.cos(ang_z),-np.sin(ang_z),0, np.sin(ang_z),np.cos(ang_z),0, 0,0,1]).reshape(3,3)
r_ax = r_ax_z.dot(r_ax_y).dot(r_ax_x)
r_ax = r_ax_z @ r_ax_y @ r_ax_x
r_ax_h = np.block([[r_ax,np.zeros(3).reshape(3,1)], [np.zeros(3), 1]])
r_ax_h__rt_h = r_ax_h.dot(rt_h)
r_ax_h__rt_h = r_ax_h @ rt_h
r = r_ax_h__rt_h[:3,:3]
t = r_ax_h__rt_h[:3,3]

View File

@ -49,7 +49,7 @@ def world_to_camera_persp(r, t):
'''
r = r.T
t = - r.dot(t)
t = - r @ t
return r, t
@ -69,10 +69,10 @@ def rotate_cam(r, t, ang_x=0, ang_y=0, ang_z=0):
r_ax_x = np.array([1,0,0, 0,np.cos(ang_x),-np.sin(ang_x), 0,np.sin(ang_x),np.cos(ang_x)]).reshape(3,3)
r_ax_y = np.array([np.cos(ang_y),0,np.sin(ang_y), 0,1,0, -np.sin(ang_y),0,np.cos(ang_y)]).reshape(3,3)
r_ax_z = np.array([np.cos(ang_z),-np.sin(ang_z),0, np.sin(ang_z),np.cos(ang_z),0, 0,0,1]).reshape(3,3)
r_ax = r_ax_z.dot(r_ax_y).dot(r_ax_x)
r_ax = r_ax_z @ r_ax_y @ r_ax_x
r_ax_h = np.block([[r_ax,np.zeros(3).reshape(3,1)], [np.zeros(3), 1]])
r_ax_h__rt_h = r_ax_h.dot(rt_h)
r_ax_h__rt_h = r_ax_h @ rt_h
r = r_ax_h__rt_h[:3,:3]
t = r_ax_h__rt_h[:3,3]

View File

@ -74,7 +74,7 @@ def world_to_camera_persp(r, t):
'''
r = r.T
t = - r.dot(t)
t = - r @ t
return r, t
@ -89,10 +89,10 @@ def rotate_cam(r, t, ang_x=np.pi, ang_y=0, ang_z=0):
r_ax_x = np.array([1,0,0, 0,np.cos(ang_x),-np.sin(ang_x), 0,np.sin(ang_x),np.cos(ang_x)]).reshape(3,3)
r_ax_y = np.array([np.cos(ang_y),0,np.sin(ang_y), 0,1,0, -np.sin(ang_y),0,np.cos(ang_y)]).reshape(3,3)
r_ax_z = np.array([np.cos(ang_z),-np.sin(ang_z),0, np.sin(ang_z),np.cos(ang_z),0, 0,0,1]).reshape(3,3)
r_ax = r_ax_z.dot(r_ax_y).dot(r_ax_x)
r_ax = r_ax_z @ r_ax_y @ r_ax_x
r_ax_h = np.block([[r_ax,np.zeros(3).reshape(3,1)], [np.zeros(3), 1]])
r_ax_h__rt_h = r_ax_h.dot(rt_h)
r_ax_h__rt_h = r_ax_h @ rt_h
r = r_ax_h__rt_h[:3,:3]
t = r_ax_h__rt_h[:3,3]

View File

@ -142,7 +142,7 @@ def computeP(calib_file, undistort=False):
T = np.array(calib[cam]['translation'])
H = np.block([[R,T.reshape(3,1)], [np.zeros(3), 1 ]])
P.append(Kh.dot(H))
P.append(Kh @ H)
return P
@ -194,8 +194,8 @@ def reprojection(P_all, Q):
x_calc, y_calc = [], []
for c in range(len(P_all)):
P_cam = P_all[c]
x_calc.append(P_cam[0].dot(Q) / P_cam[2].dot(Q))
y_calc.append(P_cam[1].dot(Q) / P_cam[2].dot(Q))
x_calc.append(P_cam[0] @ Q / (P_cam[2] @ Q))
y_calc.append(P_cam[1] @ Q / (P_cam[2] @ Q))
return x_calc, y_calc

View File

@ -191,8 +191,8 @@ elif id_kpt == ['all']:
elif len(id_kpt)==1 and len(id_kpt)==len(weights_kpt): # ex id_kpt1=9 set to 10, id_kpt2=10 to 15
# ajouter frames
dict_id_weights = {i:w for i, w in zip(id_kpt, weights_kpt)}
camx = df_speed[cam1_nb-1].dot(pd.Series(dict_id_weights).reindex(df_speed[cam1_nb-1].columns, fill_value=0))
camy = df_speed[cam2_nb-1].dot(pd.Series(dict_id_weights).reindex(df_speed[cam2_nb-1].columns, fill_value=0))
camx = df_speed[cam1_nb-1] @ pd.Series(dict_id_weights).reindex(df_speed[cam1_nb-1].columns, fill_value=0)
camy = df_speed[cam2_nb-1] @ pd.Series(dict_id_weights).reindex(df_speed[cam2_nb-1].columns, fill_value=0)
camx = camx.loc[range(np.array(frames))]
camy = camy.loc[range(np.array(frames))]
else:

View File

@ -691,8 +691,8 @@ def calibrate_extrinsics(calib_dir, extrinsics_config_dict, C, S, K, D):
# Kh_cam = np.block([mtx, np.zeros(3).reshape(3,1)])
# r_mat, _ = cv2.Rodrigues(r)
# H_cam = np.block([[r_mat,t.reshape(3,1)], [np.zeros(3), 1 ]])
# P_cam = Kh_cam.dot(H_cam)
# proj_obj = [ ( P_cam[0].dot(np.append(o, 1)) / P_cam[2].dot(np.append(o, 1)), P_cam[1].dot(np.append(o, 1)) / P_cam[2].dot(np.append(o, 1)) ) for o in objp]
# P_cam = Kh_cam @ H_cam
# proj_obj = [ ( P_cam[0] @ np.append(o, 1) / (P_cam[2] @ np.append(o, 1)), P_cam[1] @ np.append(o, 1) / (P_cam[2] @ np.append(o, 1)) ) for o in objp]
proj_obj = np.squeeze(cv2.projectPoints(objp,r,t,mtx,dist)[0])
# Check calibration results

View File

@ -99,7 +99,7 @@ def computeP(calib_file, undistort=False):
T = np.array(calib[cam]['translation'])
H = np.block([[R,T.reshape(3,1)], [np.zeros(3), 1 ]])
P.append(Kh.dot(H))
P.append(Kh @ H)
return P
@ -149,8 +149,8 @@ def reprojection(P_all, Q):
x_calc, y_calc = [], []
for c in range(len(P_all)):
P_cam = P_all[c]
x_calc.append(P_cam[0].dot(Q) / P_cam[2].dot(Q))
y_calc.append(P_cam[1].dot(Q) / P_cam[2].dot(Q))
x_calc.append(P_cam[0] @ Q / (P_cam[2] @ Q))
y_calc.append(P_cam[1] @ Q / (P_cam[2] @ Q))
return x_calc, y_calc
@ -188,7 +188,7 @@ def world_to_camera_persp(r, t):
'''
r = r.T
t = - r.dot(t)
t = - r @ t
return r, t
@ -208,10 +208,10 @@ def rotate_cam(r, t, ang_x=0, ang_y=0, ang_z=0):
r_ax_x = np.array([1,0,0, 0,np.cos(ang_x),-np.sin(ang_x), 0,np.sin(ang_x),np.cos(ang_x)]).reshape(3,3)
r_ax_y = np.array([np.cos(ang_y),0,np.sin(ang_y), 0,1,0, -np.sin(ang_y),0,np.cos(ang_y)]).reshape(3,3)
r_ax_z = np.array([np.cos(ang_z),-np.sin(ang_z),0, np.sin(ang_z),np.cos(ang_z),0, 0,0,1]).reshape(3,3)
r_ax = r_ax_z.dot(r_ax_y).dot(r_ax_x)
r_ax = r_ax_z @ r_ax_y @ r_ax_x
r_ax_h = np.block([[r_ax,np.zeros(3).reshape(3,1)], [np.zeros(3), 1]])
r_ax_h__rt_h = r_ax_h.dot(rt_h)
r_ax_h__rt_h = r_ax_h @ rt_h
r = r_ax_h__rt_h[:3,:3]
t = r_ax_h__rt_h[:3,3]