opencv - 使用 opencv - traingulatePoints 单位确定两个图像的 3D 位置

标签 opencv triangulation stereo-3d

给定一组对应点下注的两个任意(即不平行)图像(例如,通过 SURF 找到的),我使用以下方法尝试提取这些点的 3D 位置。

def triangulate(pts1,pts2):
    cameraMatrix = np.array([[1, 0,0],[0,1,0],[0,0,1]])        
    F,m1 = cv2.findFundamentalMat(pts1, pts2) # apparently not necessary

    # using the essential matrix can get you the rotation/translation bet. cameras, although there are two possible rotations: 
    E,m2 = cv2.findEssentialMat(pts1, pts2, cameraMatrix, cv2.RANSAC, 0.999, 1.0)
    Re1, Re2, t_E = cv2.decomposeEssentialMat(E)

    # recoverPose gets you an unambiguous R and t. One of the R's above does agree with the R determined here. RecoverPose can already triangulate, I check by hand below to compare results. 
    K_l = cameraMatrix
    K_r = cameraMatrix
    retval, R, t, mask2, triangulatedPoints = cv2.recoverPose(E,pts_l_norm, pts_r_norm, cameraMatrix,distanceThresh=0.5)

    # given R,t you can  explicitly find 3d locations using projection 
    M_r = np.concatenate((R,t),axis=1)
    M_l = np.concatenate((np.eye(3,3),np.zeros((3,1))),axis=1)
    proj_r = np.dot(cameraMatrix,M_r)
    proj_l = np.dot(cameraMatrix,M_l)
    points_4d_hom = cv2.triangulatePoints(proj_l, proj_r, np.expand_dims(pts1, axis=1), np.expand_dims(pts2, axis=1))
    points_4d = points_4d_hom / np.tile(point_s4d_hom[-1, :], (4, 1))
    points_3d = points_4d[:3, :].T
    return points_3d

我假设我的固有相机矩阵大约是上面的 I 。由两种方法(findEssentialMat->decomposeEssentialMat 与recoverPose)确定的R,t 一致,并且由两种方法(recoverPose 与triangulatePoints)确定的三角点也一致。我的问题涉及我看到的值,对于points_3d,x、y 的值通常在 0-50 的范围内,z 的值通常在 0-0.03 的范围内。据我所知,这些值应该以像素为单位;我对相机矩阵的选择是否影响了比例?

最佳答案

是的,您对相机矩阵的选择直接影响比例。 OpenCV 中的相机矩阵应包含 fx 和 fy 的值,它们指的是以像素单位表示的相机焦距(主距离) - see OpenCV Camera model .
如果将两个值都设置为 1,您将获得 3D 点的“较小值”(以像素为单位)。通常,(显然取决于相机)fx、fy 的值约为,例如1000。 Here您可以找到一个很好的示例,用于仅使用分辨率和近似视场 (FOV) 来估计网络摄像头的焦距。

关于opencv - 使用 opencv - traingulatePoints 单位确定两个图像的 3D 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58543362/

相关文章:

windows - OpenCV 2.3 (C++,QtGui),初始化一些特定的 USB 设备和设置时出现问题

php - OpenCV 和 Php。不可能的?

union - 多边形操作库

python - 创建五边形或更高的三角形网格

c++ - 对于简单的 StereoBM 算法,为什么我的代码比 opencv 慢得多?

opencv - 检测图像的旋转度

android - 如何将 base64 编码的 opencv java 矩阵恢复为 C++ cv::Mat?

iphone - iPhone 上的 WiFi 三角测量

python - 如何在 Python OpenCV 中用一对立体图像计算对极线

opencv - cvReprojectImageTo3D - 从 2d 图像问题进行 3d 建模-