线性三角剖分奇怪的结果

问题描述

尝试在 Python 中实现线性三角剖分并得到奇怪的结果(例如,为什么我得到一个球体以及为什么有些坐标是负数?)。不知道如何调试

我正在尝试模仿 Harley & Zisserman

enter image description here

描述的方法

数据: 来自汽车的图像。例子:

enter image description here

方法 a) 在连续图像中寻找匹配点。例子:

enter image description here

b)(可选,因为我从 GPS 知道我的旋转和平移)基本矩阵和姿势恢复以获得旋转矩阵 (R) 和平移向量 (t)

E,mask_2 = cv2.findEssentialMat(pts1,pts2,focal=focal_pixel,pp=(O_x,O_y),method=cv2.RANSAC,prob=0.999,threshold=3.0)
points,R_1,t_1,mask_2 = cv2.recoverPose(E,pts1,pts2)

c) 两幅图像的投影矩阵,第一幅图像没有旋转和平移

Pr_1 = np.hstack((np.dot(K,[[1,0],[0,1,1]]),np.dot(K,[[0],[0],[0]])))
Pr_2 = np.hstack((np.dot(K,R_2),t_2)))

d) 三角测量:

def linear_ls_triangulation(u1,P1,u2,P2):
    """Triangulation via Linear-LS method"""
    #u1 - homogenous image point (u,v,1)
    #P1 - camera 1 matrix
    #u2 - homogenous image point in 2nd camera
    #P2 - camera 2 matrix

    # build A matrix for homogeneous equation system Ax=0
    # assume X = (x,y,z,1) for Linear-LS method
    # which turns it into AX=B system,where A is 4x3,X is 3x1 & B is 4x1
    A = np.array([u1[0]*P1[2,0] - P1[0,u1[0]*P1[2,1] - P1[0,1],2] - P1[0,2],u1[1]*P1[2,0] - P1[1,1] - P1[1,2] - P1[1,u2[0]*P2[2,0] - P2[0,1] - P2[0,2] - P2[0,u2[1]*P2[2,0] - P2[1,1] - P2[1,2] - P2[1,2]]).reshape(4,3)

    B = np.array([-(u1[0]*P1[2,3] - P1[0,3]),-(u1[1]*P1[2,3] - P1[1,-(u2[0]*P2[2,3] - P2[0,-(u2[1]*P2[2,3] - P2[1,3])]).reshape(4,1)

    ret,X = cv2.solve(A,B,flags=cv2.DECOMP_SVD)
    return X.reshape(1,3)

结果:

enter image description here

enter image description here

enter image description here

完整代码在此 https://colab.research.google.com/drive/1dK9w6xqDit5T8gx91qVyjUx2kgpPpROe

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)