亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 3D 和 2D 點對應計算旋轉和平移矩陣

使用 3D 和 2D 點對應計算旋轉和平移矩陣

一只甜甜圈 2023-02-15 15:54:40
我有一組 3D 點和來自不同位置的 2D 對應點。2D 點位于 360° 全景圖上。所以我可以將它們轉換為極坐標 -> (r,theta, phi) 而沒有關于 r 的信息。但是 r 只是轉換后的 3D 點的距離:[R|t]*xyz = xyz'r = sqrt(xyz')然后 3D 點也在球坐標中,我現在可以用這個線性方程系統搜索 R 和 t:x' = sin(theta) * cos(phi) * ry' = sin(theta) * cos(phi) * rz' = sin(theta) * cos(phi) * r我在 t=[0,0,0.5] 且沒有任何旋轉的情況下得到了很好的測試結果。但如果有輪換,結果就很糟糕。這是解決我的問題的正確方法嗎?如何在沒有相機矩陣的情況下使用 solvepnp() (它是沒有失真的全景圖)?我正在使用 opt.least_squares 來計算 R 和 t。
查看完整描述

1 回答

?
寶慕林4294392

TA貢獻2021條經驗 獲得超8個贊

我用兩種不同的方法解決了它。


一種用于小旋轉并求解 R 和 t(12 個參數),另一種方法可以使用 Euler 和 t(6 個參數)計算更大的旋轉。


我opt.least_squares()用不同的初始值調用了兩次,并使用了具有更好重投影誤差的方法。


f.eul2rot 只是歐拉角和旋轉矩陣之間的轉換。


def sphere_eq(p):

    xyz_points = xyz

    uv_points = uv

    #r11,r12,r13,r21,r22,r23,r31,r32,r33,tx,ty,tz = p

    if len(p) == 12:

        r11, r12, r13, r21, r22, r23, r31, r32, r33, tx, ty, tz = p

        R = np.array([[r11, r12, r13],

                      [r21, r22, r23],

                      [r31, r32, r33]])

    else:

        gamma, beta, alpha,tx,ty,tz = p

        E = [gamma, beta, alpha]

        R = f.eul2rot(E)

    pi = np.pi

    eq_grad = ()

    for i in range(len(xyz_points)):

        # Point with Orgin: LASER in Cartesian and Spherical coordinates

        xyz_laser = np.array([xyz_points[i,0],xyz_points[i,1],xyz_points[i,2]])


        # Transformation - ROTATION MATRIX and Translation Vector

        t = np.array([[tx, ty, tz]])


        # Point with Orgin: CAMERA in Cartesian and Spherical coordinates

        uv_camera = np.array(uv_points[i])

        long_camera = ((uv_camera[0]) / w) * 2 * pi

        lat_camera = ((uv_camera[1]) / h) * pi


        xyz_camera = (R.dot(xyz_laser) + t)[0]

        r = np.linalg.norm(xyz_laser + t)


        x_eq = (xyz_camera[0] - (np.sin(lat_camera) * np.cos(long_camera) * r),)

        y_eq = (xyz_camera[1] - (np.sin(lat_camera) * np.sin(long_camera) * r),)

        z_eq = (xyz_camera[2] - (np.cos(lat_camera) *                       r),)

        eq_grad = eq_grad + x_eq + y_eq + z_eq


    return eq_grad


x = np.zeros(12)

x[0], x[4], x[8] = 1, 1, 1

initial_guess = [x,np.zeros(6)]


for p, x0 in enumerate(initial_guess):

    x = opt.least_squares(sphere_eq, x0, '3-point', method='trf')

    if len(x0) == 6:

        E = np.resize(x.x[:4], 3)

        R = f.eul2rot(E)

        t = np.resize(x.x[4:], (3, 1))

    else:

        R = np.resize(x.x[:8], (3, 3))

        E = f.rot2eul(R)

        t = np.resize(x.x[9:], (3, 1))


查看完整回答
反對 回復 2023-02-15
  • 1 回答
  • 0 關注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號