gpt4 book ai didi

python - cv2.triangulatePoints 是不是很准确?

转载 作者:行者123 更新时间:2023-12-04 12:34:04 27 4
gpt4 key购买 nike

摘要
我正在尝试从 2 张图像中对点进行三角测量,但根本没有得到准确的结果。
详情
这是我在做什么:

  • 在现实世界坐标中测量我的 16 个对象点。
  • 确定每个图像的 16 个对象点的像素坐标。
  • 使用 cv2.solvePnP() 获取每个摄像头的 tvecs 和 rvecs。
  • 使用 cv2.projectPoints 验证 tvecs 和 rvecs 是否将给定的 3D 点重新投影到正确的图像坐标(它确实有效)。例如:
    img_point_right = cv2.projectPoints(np.array([[0,0,39]], np.float), 
    right_rvecs,
    right_tvecs,
    right_intrinsics,
    right_distortion)
  • 验证后,使用此公式获取旋转矩阵:
    left_rotation, jacobian = cv2.Rodrigues(left_rvecs)
    right_rotation, jacobian = cv2.Rodrigues(right_rvecs)
    然后是投影矩阵:
    RT = np.zeros((3,4))
    RT[:3, :3] = left_rotation
    RT[:3, 3] = left_translation.transpose()
    left_projection = np.dot(left_intrinsics, RT)

    RT = np.zeros((3,4))
    RT[:3, :3] = right_rotation
    RT[:3, 3] = right_translation.transpose()
    right_projection = np.dot(right_intrinsics, RT)
  • 在三角剖分之前,使用 cv2.undistortPoints 取消扭曲点。例如:
    left_undist = cv2.undistortPoints(left_points, 
    cameraMatrix=left_intrinsics,
    distCoeffs=left_distortion)
  • 对点进行三角测量。例如:
    # Transpose to get into OpenCV's 2xN format.
    left_points_t = np.array(left_undist[0]).transpose()
    right_points_t = np.array(right_undist[0]).transpose()
    # Note, I take the 0th index of each points matrix to get rid of the extra dimension,
    # although it doesn't affect the output.

    triangulation = cv2.triangulatePoints(left_projection, right_projection, left_points_t, right_points_t)
    homog_points = triangulation.transpose()

    euclid_points = cv2.convertPointsFromHomogeneous(tri_homog)

  • 不幸的是,当我获得最后一步的输出时,尽管我试图重现具有正 Z 位置的 3D 点,但我的点甚至没有正 Z 方向。
    作为引用,正 Z 为向前,正 Y 为向下,正 X 为右。
    例如,3D 点 (0, 0, 39) - 想象一个点在你面前 39 英尺 - 给出 (4.47, -8.77, -44.81) 的三角测量输出
    问题
    这是对点进行三角测量的有效方法吗?
    如果是这样, cv2.triangulatePoints 是不是一个很好的方法来对点进行三角测量和任何替代建议?
    感谢您的帮助。

    最佳答案

    好吧,事实证明,如果我不调用 undistortPoints调用 triangulatePoints 之前的函数函数,然后我得到合理的结果。这是因为 undistortPoints在执行失真时使用内在参数对点进行归一化,但随后我仍在调用 triangulatePoints具有考虑内在参数的投影矩阵。
    然而,通过不扭曲点,然后调用 triangulatePoints,我可以获得更好的结果。使用单位矩阵作为内在矩阵构建的投影矩阵。
    问题解决了!

    关于python - cv2.triangulatePoints 是不是很准确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66361968/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com